Skip to content

Commit

Permalink
fix: convert listValues to lists
Browse files Browse the repository at this point in the history
Signed-off-by: Jesús Fernández <[email protected]>
  • Loading branch information
fernandezcuesta committed Oct 17, 2024
1 parent fde5b7e commit f6750cf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crossplane/function/proto/v1/run_function_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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__
_version_not_supported = False

Expand Down
2 changes: 1 addition & 1 deletion crossplane/function/proto/v1beta1/run_function_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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__
_version_not_supported = False

Expand Down
6 changes: 5 additions & 1 deletion crossplane/function/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ def struct_to_dict(s: structpb.Struct) -> dict:
dictionary.
"""
return {
k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else v)
k: (
struct_to_dict(v)
if isinstance(v, structpb.Struct)
else (list(v) if isinstance(v, structpb.ListValue) else v)
)
for k, v in s.items()
}

Expand Down
22 changes: 22 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,28 @@ class TestCase:
),
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:
Expand Down

0 comments on commit f6750cf

Please sign in to comment.