fix edited_attributes handling when adding entity stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 20 Aug 2009 17:57:07 +0200
branchstable
changeset 2929 51cdfe069e10
parent 2928 edfdb69df6e8
child 2930 d7c23b2c7538
fix edited_attributes handling when adding entity
server/repository.py
--- a/server/repository.py	Thu Aug 20 17:56:41 2009 +0200
+++ b/server/repository.py	Thu Aug 20 17:57:07 2009 +0200
@@ -996,15 +996,16 @@
             print 'ADD entity', etype, entity.eid, dict(entity)
         entity._is_saved = False # entity has an eid but is not yet saved
         relations = []
-        # if inlined relations are specified, fill entity's related cache to
-        # avoid unnecessary queries
+        # init edited_attributes before calling before_add_entity hooks
+        entity.edited_attributes = set(entity)
+        if source.should_call_hooks:
+            self.hm.call_hooks('before_add_entity', etype, session, entity)
+        # XXX use entity.keys here since edited_attributes is not updated for
+        # inline relations
         for attr in entity.keys():
             rschema = eschema.subject_relation(attr)
             if not rschema.is_final(): # inlined relation
                 relations.append((attr, entity[attr]))
-        if source.should_call_hooks:
-            self.hm.call_hooks('before_add_entity', etype, session, entity)
-        entity.edited_attributes = set(entity)
         entity.set_defaults()
         entity.check(creation=True)
         source.add_entity(session, entity)