Fixes bug with appending post save - due to lists not being reset
This commit is contained in:
parent
08ba51f714
commit
09c32a63ce
@ -161,7 +161,18 @@ class Document(BaseDocument):
|
|||||||
raise OperationError(message % unicode(err))
|
raise OperationError(message % unicode(err))
|
||||||
id_field = self._meta['id_field']
|
id_field = self._meta['id_field']
|
||||||
self[id_field] = self._fields[id_field].to_python(object_id)
|
self[id_field] = self._fields[id_field].to_python(object_id)
|
||||||
self._changed_fields = []
|
|
||||||
|
def reset_changed_fields(doc):
|
||||||
|
"""Loop through and reset changed fields lists"""
|
||||||
|
if hasattr(doc, '_changed_fields'):
|
||||||
|
doc._changed_fields = []
|
||||||
|
|
||||||
|
for field_name in doc._fields:
|
||||||
|
field = getattr(doc, field_name)
|
||||||
|
if hasattr(field, '_changed_fields') and field != doc:
|
||||||
|
reset_changed_fields(field)
|
||||||
|
|
||||||
|
reset_changed_fields(self)
|
||||||
signals.post_save.send(self.__class__, document=self, created=created)
|
signals.post_save.send(self.__class__, document=self, created=created)
|
||||||
|
|
||||||
def delete(self, safe=False):
|
def delete(self, safe=False):
|
||||||
|
@ -879,7 +879,7 @@ class FieldTest(unittest.TestCase):
|
|||||||
name = StringField()
|
name = StringField()
|
||||||
children = ListField(EmbeddedDocumentField('self'))
|
children = ListField(EmbeddedDocumentField('self'))
|
||||||
|
|
||||||
Tree.drop_collection
|
Tree.drop_collection()
|
||||||
tree = Tree(name="Tree")
|
tree = Tree(name="Tree")
|
||||||
|
|
||||||
first_child = TreeNode(name="Child 1")
|
first_child = TreeNode(name="Child 1")
|
||||||
@ -887,9 +887,15 @@ class FieldTest(unittest.TestCase):
|
|||||||
|
|
||||||
second_child = TreeNode(name="Child 2")
|
second_child = TreeNode(name="Child 2")
|
||||||
first_child.children.append(second_child)
|
first_child.children.append(second_child)
|
||||||
|
tree.save()
|
||||||
|
|
||||||
|
tree = Tree.objects.first()
|
||||||
|
self.assertEqual(len(tree.children), 1)
|
||||||
|
|
||||||
|
self.assertEqual(len(tree.children[0].children), 1)
|
||||||
|
|
||||||
third_child = TreeNode(name="Child 3")
|
third_child = TreeNode(name="Child 3")
|
||||||
first_child.children.append(third_child)
|
tree.children[0].children.append(third_child)
|
||||||
tree.save()
|
tree.save()
|
||||||
|
|
||||||
self.assertEqual(len(tree.children), 1)
|
self.assertEqual(len(tree.children), 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user