fix change tracking for ComplexBaseFields
This commit is contained in:
parent
c5ce96c391
commit
c0571beec8
@ -205,12 +205,6 @@ class ComplexBaseField(BaseField):
|
||||
|
||||
return value
|
||||
|
||||
def __set__(self, instance, value):
|
||||
"""Descriptor for assigning a value to a field in a document.
|
||||
"""
|
||||
instance._data[self.name] = value
|
||||
instance._mark_as_changed(self.name)
|
||||
|
||||
def to_python(self, value):
|
||||
"""Convert a MongoDB-compatible type to a Python type.
|
||||
"""
|
||||
|
@ -808,6 +808,27 @@ class FieldTest(unittest.TestCase):
|
||||
|
||||
self.assertRaises(ValidationError, e.save)
|
||||
|
||||
def test_complex_field_same_value_not_changed(self):
|
||||
"""
|
||||
If a complex field is set to the same value, it should not be marked as
|
||||
changed.
|
||||
"""
|
||||
class Simple(Document):
|
||||
mapping = ListField()
|
||||
|
||||
Simple.drop_collection()
|
||||
e = Simple().save()
|
||||
e.mapping = []
|
||||
self.assertEqual([], e._changed_fields)
|
||||
|
||||
class Simple(Document):
|
||||
mapping = DictField()
|
||||
|
||||
Simple.drop_collection()
|
||||
e = Simple().save()
|
||||
e.mapping = {}
|
||||
self.assertEqual([], e._changed_fields)
|
||||
|
||||
def test_list_field_complex(self):
|
||||
"""Ensure that the list fields can handle the complex types."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user