[repository] fix edited_attributes management in multiple SET queries stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 12 Apr 2010 08:22:37 +0200
branchstable
changeset 5213 8604000bf3b2
parent 5212 a545eb9add6f
child 5215 b1327f19d23e
[repository] fix edited_attributes management in multiple SET queries entity.edited_attributes was messed up with previous edited entities. The UpdateStep now gives a new fresh edited_attributes set to repository.glob_update_entity() so that each entity can modify it during its "transaction".
server/ssplanner.py
server/test/unittest_repository.py
--- a/server/ssplanner.py	Mon Apr 12 08:17:35 2010 +0200
+++ b/server/ssplanner.py	Mon Apr 12 08:22:37 2010 +0200
@@ -577,7 +577,7 @@
             result[i] = newrow
         # update entities
         for eid, edef in edefs.iteritems():
-            repo.glob_update_entity(session, edef, self.attributes)
+            repo.glob_update_entity(session, edef, set(self.attributes))
         return result
 
 def _handle_relterm(info, row, newrow):
--- a/server/test/unittest_repository.py	Mon Apr 12 08:17:35 2010 +0200
+++ b/server/test/unittest_repository.py	Mon Apr 12 08:22:37 2010 +0200
@@ -400,6 +400,27 @@
             self.assertRaises(AssertionError, req.create_entity,
                               'EmailAddress', address=u'a@b.fr')
 
+    def test_multiple_edit_set_attributes(self):
+        """make sure edited_attributes doesn't get cluttered
+        by previous entities on multiple set
+        """
+        # local hook
+        class DummyBeforeHook(Hook):
+            _test = self # keep reference to test instance
+            __regid__ = 'dummy-before-hook'
+            __select__ = Hook.__select__ & implements('Affaire')
+            events = ('before_update_entity',)
+            def __call__(self):
+                # invoiced attribute shouldn't be considered "edited" before the hook
+                self._test.failIf('invoiced' in self.entity.edited_attributes,
+                                  'edited_attributes cluttered by previous update')
+                self.entity['invoiced'] = 10
+        with self.temporary_appobjects(DummyBeforeHook):
+            req = self.request()
+            req.create_entity('Affaire', ref=u'AFF01')
+            req.create_entity('Affaire', ref=u'AFF02')
+            req.execute('SET A duration 10 WHERE A is Affaire')
+
 
 class DataHelpersTC(CubicWebTC):