# HG changeset patch # User Julien Cristau # Date 1421333109 -3600 # Node ID 116b24efad0e4e4d6407be8c73e53b2374687ed2 # Parent 215403b9798f99e97cb62d12d4bc33532b77130c [hooks] don't insert an owned_by relation for deleted entities If, in the same transaction, a composed entity is created and deleted, we'll have scheduled a SyncOwnersOp which would end up creating an owned_by relation for the deleted entity. Closes #4846883 diff -r 215403b9798f -r 116b24efad0e hooks/metadata.py --- a/hooks/metadata.py Thu Jan 29 16:18:23 2015 +0100 +++ b/hooks/metadata.py Thu Jan 15 15:45:09 2015 +0100 @@ -93,6 +93,10 @@ class SyncOwnersOp(hook.DataOperationMixIn, hook.Operation): def precommit_event(self): for compositeeid, composedeid in self.get_data(): + if self.cnx.deleted_in_transaction(compositeeid): + continue + if self.cnx.deleted_in_transaction(composedeid): + continue self.cnx.execute('SET X owned_by U WHERE C owned_by U, C eid %(c)s,' 'NOT EXISTS(X owned_by U, X eid %(x)s)', {'c': compositeeid, 'x': composedeid}) diff -r 215403b9798f -r 116b24efad0e hooks/test/unittest_hooks.py --- a/hooks/test/unittest_hooks.py Thu Jan 29 16:18:23 2015 +0100 +++ b/hooks/test/unittest_hooks.py Thu Jan 15 15:45:09 2015 +0100 @@ -184,6 +184,17 @@ 'U login "toto", X address A')[0][0], 'toto@logilab.fr') + def test_user_composite_no_owner_on_deleted_entity(self): + with self.admin_access.repo_cnx() as cnx: + u = self.create_user(cnx, 'toto').eid + cnx.commit() + e = cnx.create_entity('EmailAddress', address=u'toto@logilab.fr', reverse_use_email=u) + e.cw_delete() + cnx.commit() + self.assertFalse(cnx.system_sql( + 'SELECT * FROM owned_by_relation ' + 'WHERE eid_from NOT IN (SELECT eid FROM entities)').fetchall()) + def test_no_created_by_on_deleted_entity(self): with self.admin_access.repo_cnx() as cnx: eid = cnx.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0]