File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,9 @@ def struct_to_dict(s: structpb.Struct) -> dict:
7070 dictionary.
7171 """
7272 return {
73- k : (struct_to_dict (v ) if isinstance (v , structpb .Struct ) else v )
73+ k : (struct_to_dict (v ) if isinstance (v , structpb .Struct ) else (
74+ list (v ) if isinstance (v , structpb .ListValue ) else v
75+ ))
7476 for k , v in s .items ()
7577 }
7678
Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments