From 3baeb4b64e130eeb6eb56c07ad95d57cb2383b36 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 23 Jan 2024 20:05:24 +0100 Subject: [PATCH] Fix initializing a sub-model instance from a dictionary --- osc/util/models.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osc/util/models.py b/osc/util/models.py index ab65b64f..174a7bec 100644 --- a/osc/util/models.py +++ b/osc/util/models.py @@ -252,10 +252,9 @@ class Field(property): def set(self, obj, value): # if this is a model field, convert dict to a model instance if self.is_model and isinstance(value, dict): - new_value = self.origin_type() # pylint: disable=not-callable - for k, v in value.items(): - setattr(new_value, k, v) - value = new_value + # initialize a model instance from a dictionary + klass = self.origin_type + value = klass(**value) # pylint: disable=not-callable self.validate_type(value) obj._values[self.name] = value