1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-31 18:34:11 +02:00

Fix exporting an empty model field in BaseModel.dict()

This commit is contained in:
2024-01-23 20:05:28 +01:00
parent 3baeb4b64e
commit b4a1b29f57
2 changed files with 8 additions and 3 deletions

View File

@@ -339,8 +339,10 @@ class BaseModel(metaclass=ModelMeta):
for name, field in self.__fields__.items():
if field.exclude:
continue
if field.is_model:
result[name] = getattr(self, name).dict()
value = getattr(self, name)
if value is not None and field.is_model:
result[name] = value.dict()
else:
result[name] = getattr(self, name)
result[name] = value
return result