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:
Jesús Fernández 2024-10-18 01:37:51 +02:00
parent fde5b7ef84
commit 25e49cf3bd
No known key found for this signature in database
GPG Key ID: F009C46F547D9A66
4 changed files with 26 additions and 6 deletions

View File

@ -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
GRPC_GENERATED_VERSION = '1.66.0'
GRPC_GENERATED_VERSION = '1.66.2'
GRPC_VERSION = grpc.__version__
_version_not_supported = False

View File

@ -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
GRPC_GENERATED_VERSION = '1.66.0'
GRPC_GENERATED_VERSION = '1.66.2'
GRPC_VERSION = grpc.__version__
_version_not_supported = False

View File

@ -18,6 +18,7 @@ import dataclasses
import datetime
import pydantic
from google.protobuf import json_format
from google.protobuf import struct_pb2 as structpb
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
dictionary.
"""
return {
k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else v)
for k, v in s.items()
}
return json_format.MessageToDict(s, preserving_proto_field_name=True)
@dataclasses.dataclass

View File

@ -275,6 +275,28 @@ class TestResource(unittest.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: