[hooks] Propery handle case of data-object deletion in hook synchronizing file_category changes
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 13 Dec 2017 09:53:46 +0100
changeset 2925 5af6328d0b3d
parent 2924 919faf33df18
child 2926 9d8dcc178c64
[hooks] Propery handle case of data-object deletion in hook synchronizing file_category changes Since the operation may be triggered by deletion of the relation, it may be unadvertanly called by cascade when the data-object is being deleted.
cubicweb_seda/hooks.py
test/test_hooks.py
--- a/cubicweb_seda/hooks.py	Tue Dec 12 18:25:40 2017 +0100
+++ b/cubicweb_seda/hooks.py	Wed Dec 13 09:53:46 2017 +0100
@@ -473,6 +473,8 @@
 
     def precommit_event(self):
         for bdo_eid in self.get_data():
+            if self.cnx.deleted_in_transaction(bdo_eid):
+                continue
             bdo = self.cnx.entity_from_eid(bdo_eid)
             if not bdo.container:
                 # we may have to clear the container cache if the parent has
--- a/test/test_hooks.py	Tue Dec 12 18:25:40 2017 +0100
+++ b/test/test_hooks.py	Wed Dec 13 09:53:46 2017 +0100
@@ -275,6 +275,11 @@
                                    ['application/msword', 'application/pdf'],
                                    ['fmt/37', 'fmt/38', 'fmt/14'])
 
+            # ensure deleting the data object doesn't raise an exception because
+            # of erroneous hook
+            bdo.cw_delete()
+            cnx.commit()
+
     def test_join(self):
         with self.admin_access.cnx() as cnx:
             transfer = cnx.entity_from_eid(self.transfer_eid)