mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-23 13:31:48 +01:00
Store model values in self._values dict instead of private attributes
This commit is contained in:
parent
31059f0f92
commit
3c733387af
@ -205,8 +205,8 @@ class Field(property):
|
|||||||
|
|
||||||
def get(self, obj):
|
def get(self, obj):
|
||||||
try:
|
try:
|
||||||
return getattr(obj, f"_{self.name}")
|
return obj._values[self.name]
|
||||||
except AttributeError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if isinstance(self.default, FromParent):
|
if isinstance(self.default, FromParent):
|
||||||
@ -239,7 +239,7 @@ class Field(property):
|
|||||||
value = new_value
|
value = new_value
|
||||||
|
|
||||||
self.validate_type(value)
|
self.validate_type(value)
|
||||||
setattr(obj, f"_{self.name}", value)
|
obj._values[self.name] = value
|
||||||
self.is_set = True
|
self.is_set = True
|
||||||
|
|
||||||
|
|
||||||
@ -281,6 +281,7 @@ class BaseModel(metaclass=ModelMeta):
|
|||||||
__fields__: Dict[str, Field]
|
__fields__: Dict[str, Field]
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
self._values = {}
|
||||||
self._parent = kwargs.pop("_parent", None)
|
self._parent = kwargs.pop("_parent", None)
|
||||||
|
|
||||||
uninitialized_fields = []
|
uninitialized_fields = []
|
||||||
|
Loading…
Reference in New Issue
Block a user