1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-06 06:46:14 +01:00

Fix initializing a sub-model instance from a dictionary

This commit is contained in:
Daniel Mach 2024-01-23 20:05:24 +01:00
parent 35433fc341
commit 3baeb4b64e

View File

@ -252,10 +252,9 @@ class Field(property):
def set(self, obj, value): def set(self, obj, value):
# if this is a model field, convert dict to a model instance # if this is a model field, convert dict to a model instance
if self.is_model and isinstance(value, dict): if self.is_model and isinstance(value, dict):
new_value = self.origin_type() # pylint: disable=not-callable # initialize a model instance from a dictionary
for k, v in value.items(): klass = self.origin_type
setattr(new_value, k, v) value = klass(**value) # pylint: disable=not-callable
value = new_value
self.validate_type(value) self.validate_type(value)
obj._values[self.name] = value obj._values[self.name] = value