Merge pull request #344 from matchbox/complex-change-tracking

Remove custom change tracking for ComplexBaseFields just use BaseField's one
This commit is contained in:
Ross Lawley 2013-06-04 02:54:59 -07:00
commit 3b60adc8da
2 changed files with 21 additions and 6 deletions

View File

@ -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.
"""

View File

@ -880,6 +880,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."""