Skip to content

Commit bf0da33

Browse files
authored
fix(serializer): list type representation error
1 parent 7d5a61e commit bf0da33

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

rootfs/api/serializers/__init__.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,22 @@ def to_internal_value(self, data):
8686

8787
def to_representation(self, obj):
8888
"""Serialize the field's JSON data, for read operations."""
89-
for k, v in obj.items():
90-
if v is None: # NoneType is used to unset a value
91-
continue
92-
93-
try:
94-
if isinstance(v, (dict, list)):
95-
self.to_representation(v)
96-
elif self.convert_to_str:
97-
obj[k] = str(v)
98-
except ValueError:
99-
obj[k] = v
100-
# Do nothing, the validator will catch this later
89+
if isinstance(obj, dict):
90+
for k, v in obj.items():
91+
if v is None: # NoneType is used to unset a value
92+
continue
10193

94+
try:
95+
if isinstance(v, (dict, list)):
96+
self.to_representation(v)
97+
elif self.convert_to_str:
98+
obj[k] = str(v)
99+
except ValueError:
100+
obj[k] = v
101+
# Do nothing, the validator will catch this later
102+
elif isinstance(obj, list):
103+
for i in range(len(obj)):
104+
obj[i] = self.to_representation(obj[i])
102105
return obj
103106

104107

0 commit comments

Comments
 (0)