Skip to content

Commit 25e49cf

Browse files
fix: structs containing listvalues are properly converted
Signed-off-by: Jesús Fernández <[email protected]>
1 parent fde5b7e commit 25e49cf

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

crossplane/function/proto/v1/run_function_pb2_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from crossplane.function.proto.v1 import run_function_pb2 as crossplane_dot_function_dot_proto_dot_v1_dot_run__function__pb2
77

8-
GRPC_GENERATED_VERSION = '1.66.0'
8+
GRPC_GENERATED_VERSION = '1.66.2'
99
GRPC_VERSION = grpc.__version__
1010
_version_not_supported = False
1111

crossplane/function/proto/v1beta1/run_function_pb2_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from crossplane.function.proto.v1beta1 import run_function_pb2 as crossplane_dot_function_dot_proto_dot_v1beta1_dot_run__function__pb2
77

8-
GRPC_GENERATED_VERSION = '1.66.0'
8+
GRPC_GENERATED_VERSION = '1.66.2'
99
GRPC_VERSION = grpc.__version__
1010
_version_not_supported = False
1111

crossplane/function/resource.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import datetime
1919

2020
import pydantic
21+
from google.protobuf import json_format
2122
from google.protobuf import struct_pb2 as structpb
2223

2324
import crossplane.function.proto.v1.run_function_pb2 as fnv1
@@ -69,10 +70,7 @@ def struct_to_dict(s: structpb.Struct) -> dict:
6970
protobuf struct. This function makes it possible to convert resources to a
7071
dictionary.
7172
"""
72-
return {
73-
k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else v)
74-
for k, v in s.items()
75-
}
73+
return json_format.MessageToDict(s, preserving_proto_field_name=True)
7674

7775

7876
@dataclasses.dataclass

tests/test_resource.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,28 @@ class TestCase:
275275
),
276276
want={"foo": {"bar": "baz"}},
277277
),
278+
TestCase(
279+
reason="Convert a nested struct containing ListValues to a dictionary.",
280+
s=structpb.Struct(
281+
fields={
282+
"foo": structpb.Value(
283+
struct_value=structpb.Struct(
284+
fields={
285+
"bar": structpb.Value(
286+
list_value=structpb.ListValue(
287+
values=[
288+
structpb.Value(string_value="baz"),
289+
structpb.Value(string_value="qux"),
290+
]
291+
)
292+
)
293+
}
294+
)
295+
)
296+
}
297+
),
298+
want={"foo": {"bar": ["baz", "qux"]}},
299+
),
278300
]
279301

280302
for case in cases:

0 commit comments

Comments
 (0)