[entity] we also have to override dict.pop to properly maintain edited_attributes consistency stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Mar 2010 13:42:17 +0100
branchstable
changeset 5009 2ac04bc976c3
parent 5008 385bf22e3c12
child 5010 b2c5aee8ca3f
[entity] we also have to override dict.pop to properly maintain edited_attributes consistency
entity.py
--- a/entity.py	Thu Mar 25 13:41:26 2010 +0100
+++ b/entity.py	Thu Mar 25 13:42:17 2010 +0100
@@ -286,6 +286,18 @@
             self.edited_attributes.add(attr)
             self.skip_security_attributes.add(attr)
 
+    def pop(self, attr, default=_marker):
+        """override pop to update self.edited_attributes on cleanup of
+        undesired changes introduced in the entity's dict. See `__delitem__`
+        """
+        if default is _marker:
+            value = super(Entity, self).pop(attr)
+        else:
+            value = super(Entity, self).pop(attr, default)
+        if hasattr(self, 'edited_attributes') and attr in self.edited_attributes:
+            self.edited_attributes.remove(attr)
+        return value
+
     def rql_set_value(self, attr, value):
         """call by rql execution plan when some attribute is modified