[PATCH 2 of 2 seda] [hooks] Delete binary DO when deleting an archive unit not related to a profile

Denis Laxalde denis.laxalde at logilab.fr
Fri Dec 14 10:10:13 CET 2018

# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1544777854 -3600
#      Fri Dec 14 09:57:34 2018 +0100
# Node ID 30e67f4f9e298b04b95148a7d48e3868004728d4
# Parent  049322b9d8eeb3e954a91ebeeef5a5aaf5ca8a58
# Available At http://hg.logilab.org/review/cubes/seda
#              hg pull http://hg.logilab.org/review/cubes/seda -r 30e67f4f9e29
[hooks] Delete binary DO when deleting an archive unit not related to a profile

We extend the logic of "seda.doref.del" hook so that it not only handles
the case of "simplified profile" but also the case of archive unit not
related to a profile. In the later case, we check that the container of
"SEDABinaryDataObject" is really a "SEDAArchiveUnit" (not sure what else
it could be) and trigger the operation deleting the binary data-object
when its parent object reference (SEDADataObjectReference entity) is

Accordingly, we rename hook and operation classes and update their

This resolves CONSEJIRA-643 but making deletion of an archive unit
containing a binary data object but not related to profile. New test
goes into test_schema.py below other tests related to the hook we

diff --git a/cubicweb_seda/hooks.py b/cubicweb_seda/hooks.py
--- a/cubicweb_seda/hooks.py
+++ b/cubicweb_seda/hooks.py
@@ -298,9 +298,9 @@ class SimplifiedProfileSyncDORefCardOp(h
-class SimplifiedProfileDelRefROHook(hook.Hook):
+class DeleleBDOWhenDeletingDORefHook(hook.Hook):
     """Hook triggering an operation to delete the data object associated to a
-    reference when the later is deleted from a simplified profile.
+    reference when the later is deleted from a simplified profile or an archive unit.
     __regid__ = 'seda.doref.del'
     __select__ = hook.Hook.__select__ & hook.match_rtype('seda_data_object_reference_id')
@@ -314,13 +314,17 @@ class SimplifiedProfileDelRefROHook(hook
                 container = bdo.seda_binary_data_object[0]
                 if not container.simplified_profile:
-            SimplifiedProfileDelRefROOp(self._cw, do_ref=ref, do=bdo)
+            else:
+                if not bdo.container or bdo.container[0].cw_etype != 'SEDAArchiveUnit':
+                    return
+            DeleleBDOAlongWithDORefOp(self._cw, do_ref=ref, do=bdo)
-class SimplifiedProfileDelRefROOp(hook.Operation):
+class DeleleBDOAlongWithDORefOp(hook.Operation):
     """Delete data object whose former reference has been deleted in the
     transaction. Expected to be run only if the profile is a simplified
-    profile.
+    profile or if the data object is related to an archive unit not itself
+    related to profile.
     def precommit_event(self):
diff --git a/test/test_schema.py b/test/test_schema.py
--- a/test/test_schema.py
+++ b/test/test_schema.py
@@ -279,6 +279,19 @@ class SchemaTC(CubicWebTC):
                 len(cnx.execute('Any X WHERE X eid %(x)s', {'x': bdo.eid})),
                 0 if simplified else 1)
+    def test_delete_archiveunit_with_data_object(self):
+        """Make sure deletion of an archive unit with a binary data object,
+        but not related to an archive transfer is possible.
+        """
+        with self.admin_access.cnx() as cnx:
+            unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(None, cnx=cnx)
+            bdo = testutils.create_data_object(unit_alt_seq)
+            cnx.commit()
+            bdo.cw_clear_all_caches()
+            unit.cw_delete()
+            cnx.commit()
+            self.assertFalse(cnx.execute('Any X WHERE X eid %(x)s', {'x': bdo.eid}))
 class SecurityTC(CubicWebTC):

More information about the saem-devel mailing list