Allow assignment of NO_VALUE to fields

This commit is contained in:
Itai Shirav 2020-05-28 23:02:55 +03:00
parent 56cf86a246
commit f0bef7f75d
2 changed files with 5 additions and 1 deletions

View File

@ -170,7 +170,7 @@ class Model(metaclass=ModelBase):
This may raise a `ValueError`.
'''
field = self.get_field(name)
if field:
if field and (value != NO_VALUE):
try:
value = field.to_python(value, pytz.utc)
field.validate(value)

View File

@ -60,6 +60,10 @@ class AliasFieldsTest(unittest.TestCase):
def test_default_value(self):
instance = ModelWithAliasFields()
self.assertEqual(instance.alias_str, NO_VALUE)
# Check that NO_VALUE can be assigned to a field
instance.str_field = NO_VALUE
# Check that NO_VALUE can be assigned when creating a new instance
instance2 = ModelWithAliasFields(**instance.to_dict())
class ModelWithAliasFields(Model):