fix: structs containing listvalues are properly converted
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
This commit is contained in:
parent
fde5b7ef84
commit
25e49cf3bd
|
@ -5,7 +5,7 @@ import warnings
|
||||||
|
|
||||||
from crossplane.function.proto.v1 import run_function_pb2 as crossplane_dot_function_dot_proto_dot_v1_dot_run__function__pb2
|
from crossplane.function.proto.v1 import run_function_pb2 as crossplane_dot_function_dot_proto_dot_v1_dot_run__function__pb2
|
||||||
|
|
||||||
GRPC_GENERATED_VERSION = '1.66.0'
|
GRPC_GENERATED_VERSION = '1.66.2'
|
||||||
GRPC_VERSION = grpc.__version__
|
GRPC_VERSION = grpc.__version__
|
||||||
_version_not_supported = False
|
_version_not_supported = False
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import warnings
|
||||||
|
|
||||||
from crossplane.function.proto.v1beta1 import run_function_pb2 as crossplane_dot_function_dot_proto_dot_v1beta1_dot_run__function__pb2
|
from crossplane.function.proto.v1beta1 import run_function_pb2 as crossplane_dot_function_dot_proto_dot_v1beta1_dot_run__function__pb2
|
||||||
|
|
||||||
GRPC_GENERATED_VERSION = '1.66.0'
|
GRPC_GENERATED_VERSION = '1.66.2'
|
||||||
GRPC_VERSION = grpc.__version__
|
GRPC_VERSION = grpc.__version__
|
||||||
_version_not_supported = False
|
_version_not_supported = False
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import dataclasses
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import pydantic
|
import pydantic
|
||||||
|
from google.protobuf import json_format
|
||||||
from google.protobuf import struct_pb2 as structpb
|
from google.protobuf import struct_pb2 as structpb
|
||||||
|
|
||||||
import crossplane.function.proto.v1.run_function_pb2 as fnv1
|
import crossplane.function.proto.v1.run_function_pb2 as fnv1
|
||||||
|
@ -69,10 +70,7 @@ def struct_to_dict(s: structpb.Struct) -> dict:
|
||||||
protobuf struct. This function makes it possible to convert resources to a
|
protobuf struct. This function makes it possible to convert resources to a
|
||||||
dictionary.
|
dictionary.
|
||||||
"""
|
"""
|
||||||
return {
|
return json_format.MessageToDict(s, preserving_proto_field_name=True)
|
||||||
k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else v)
|
|
||||||
for k, v in s.items()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
|
|
|
@ -275,6 +275,28 @@ class TestResource(unittest.TestCase):
|
||||||
),
|
),
|
||||||
want={"foo": {"bar": "baz"}},
|
want={"foo": {"bar": "baz"}},
|
||||||
),
|
),
|
||||||
|
TestCase(
|
||||||
|
reason="Convert a nested struct containing ListValues to a dictionary.",
|
||||||
|
s=structpb.Struct(
|
||||||
|
fields={
|
||||||
|
"foo": structpb.Value(
|
||||||
|
struct_value=structpb.Struct(
|
||||||
|
fields={
|
||||||
|
"bar": structpb.Value(
|
||||||
|
list_value=structpb.ListValue(
|
||||||
|
values=[
|
||||||
|
structpb.Value(string_value="baz"),
|
||||||
|
structpb.Value(string_value="qux"),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
want={"foo": {"bar": ["baz", "qux"]}},
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
for case in cases:
|
for case in cases:
|
||||||
|
|
Loading…
Reference in New Issue