mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Fixed default autoserialization values...
This commit is contained in:
parent
ea91006b77
commit
0c3a1d746e
@ -540,20 +540,19 @@ class AutoSerializable(Serializable, metaclass=_FieldNameSetter):
|
||||
|
||||
for _, v in self._all_fields_attrs():
|
||||
if isinstance(v, _SerializableField):
|
||||
if v.name in fields and fields[v.name].type_name == str(v.__class__.__name__):
|
||||
v.unmarshal(self, fields[v.name].value)
|
||||
else:
|
||||
# If field is not found, or type is not the same, set default value
|
||||
if not v.name in fields:
|
||||
logger.warning('Field %s not found in unmarshalled data', v.name)
|
||||
if v.name in fields:
|
||||
if fields[v.name].type_name == str(v.__class__.__name__):
|
||||
v.unmarshal(self, fields[v.name].value)
|
||||
else:
|
||||
v.__set__(self, v._default())
|
||||
logger.warning(
|
||||
'Field %s has wrong type in unmarshalled data (should be %s and is %s',
|
||||
v.name,
|
||||
fields[v.name].type_name,
|
||||
v.__class__.__name__,
|
||||
)
|
||||
else:
|
||||
logger.debug('Field %s not found in unmarshalled data', v.name)
|
||||
v.__set__(self, v._default()) # Set default value
|
||||
|
||||
def __eq__(self, other: typing.Any) -> bool:
|
||||
"""
|
||||
|
@ -261,6 +261,12 @@ class AutoSerializable(UDSTestCase):
|
||||
data = instance.marshal()
|
||||
|
||||
instance2 = AutoSerializableClass()
|
||||
# Overwrite defaults, so we can check that they are restored on unmarshal
|
||||
instance2.str_field = UNICODE_CHARS
|
||||
instance2.float_field = 3.0
|
||||
instance2.dict_field = {'a': 11, 'b': 22, 'c': 33}
|
||||
instance2.obj_dc_field = SerializableDataclass(11, '22', 33.0)
|
||||
|
||||
instance2.unmarshal(data)
|
||||
|
||||
self.assertNotEqual(instance2, instance)
|
||||
|
Loading…
Reference in New Issue
Block a user