[PATCH seda] [hooks] Propery handle case of data-object deletion in hook synchronizing file_category changes

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Dec 13 09:55:54 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1513155226 -3600
#      Wed Dec 13 09:53:46 2017 +0100
# Node ID db4351e488d4d9dd08209fad232a44c7f95d83f3
# Parent  60b3750505c2d21e35bc2cae0d28048691f12531
# Available At https://hg.logilab.org/review/cubes/seda
#              hg pull https://hg.logilab.org/review/cubes/seda -r db4351e488d4
[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.

diff --git a/cubicweb_seda/hooks.py b/cubicweb_seda/hooks.py
--- a/cubicweb_seda/hooks.py
+++ b/cubicweb_seda/hooks.py
@@ -471,10 +471,12 @@ class SyncFileCategoryOp(hook.DataOperat
         '          NOT EXISTS(CAT2 broader_concept Z2))'
     )
 
     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
                 # been added in the same transaction
                 bdo.cw_clear_relation_cache('container', 'subject')
diff --git a/test/test_hooks.py b/test/test_hooks.py
--- a/test/test_hooks.py
+++ b/test/test_hooks.py
@@ -273,10 +273,15 @@ class DispatchFileCategoryTC(CubicWebTC)
             imported_bdo, = [x for x in transfer.binary_data_objects if x.eid != bdo.eid]
             self.assertFormatEqual(imported_bdo,
                                    ['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)
             bdo = cnx.entity_from_eid(self.bdo_eid)
 


More information about the saem-devel mailing list