only mark a field as changed if the value has changed

Prevents spurious changes from being recorded.
This commit is contained in:
Paul Swartz 2013-03-25 10:59:31 -04:00
parent 9f58bc9207
commit faf840f924
2 changed files with 7 additions and 8 deletions

View File

@ -128,3 +128,4 @@ that much better:
* Peter Teichman
* Jakub Kot
* Jorge Bastida
* Paul Swartz

View File

@ -205,8 +205,12 @@ class BaseField(object):
def __set__(self, instance, value):
"""Descriptor for assigning a value to a field in a document.
"""
instance._data[self.name] = value
if instance._initialised:
changed = False
if (self.name not in instance._data or
instance._data[self.name] != value):
changed = True
instance._data[self.name] = value
if changed and instance._initialised:
instance._mark_as_changed(self.name)
def error(self, message="", errors=None, field_name=None):
@ -317,12 +321,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.
"""