[PATCH seda] Fix problem with cloning seda_data_object_reference_id

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Dec 12 18:26:43 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1513099540 -3600
#      Tue Dec 12 18:25:40 2017 +0100
# Node ID d968f8deed5bfd5fd29a353875410945c7c2d6da
# Parent  ee68ebb504d237582b36773c47628cf8dc9ca288
# Available At https://hg.logilab.org/review/cubes/seda
#              hg pull https://hg.logilab.org/review/cubes/seda -r d968f8deed5b
Fix problem with cloning seda_data_object_reference_id

introduced by c463fd270e81

This should be specially handled even when the cloning starts from the archive
transfer.

diff --git a/cubicweb_seda/entities/__init__.py b/cubicweb_seda/entities/__init__.py
--- a/cubicweb_seda/entities/__init__.py
+++ b/cubicweb_seda/entities/__init__.py
@@ -165,21 +165,19 @@ class DirectLinkIContained(IContained):
 class SEDAArchiveTransferIClonableAdapter(IClonableAdapter):
     """Cloning adapter for SEDA profiles."""
     __select__ = is_instance('SEDAArchiveTransfer')
     rtype = 'clone_of'
     skiprtypes = ('container',)
-
-
-class SEDAArchiveUnitIClonableAdapter(IClonableAdapter):
-    """Cloning adapter for SEDA components."""
-    __select__ = is_instance('SEDAArchiveUnit')
-    rtype = 'clone_of'
-    skiprtypes = ('container',)
     # this relation isn't composite but it should be followed for cloning since
     # it's an intra-container relation
     follow_relations = [('seda_data_object_reference_id', 'subject')]
 
+
+class SEDAArchiveUnitIClonableAdapter(SEDAArchiveTransferIClonableAdapter):
+    """Cloning adapter for SEDA components."""
+    __select__ = is_instance('SEDAArchiveUnit')
+
     def clone_into(self, clone):
         """Recursivily clone the container graph of this entity into `clone`."""
         if clone.seda_archive_unit and (
                 clone.seda_archive_unit[0].cw_etype == 'SEDAArchiveTransfer'
                 or clone.seda_archive_unit[0].container[0].cw_etype == 'SEDAArchiveTransfer'):
diff --git a/test/test_entities.py b/test/test_entities.py
--- a/test/test_entities.py
+++ b/test/test_entities.py
@@ -1,6 +1,6 @@
-# copyright 2016-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr -- mailto:contact at logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Lesser General Public License as published by the Free
 # Software Foundation, either version 2.1 of the License, or (at your option)
@@ -164,10 +164,34 @@ class ContainerTC(CubicWebTC):
             self.assertEqual(cloned.seda_alt_archive_unit_archive_unit_ref_id[0].container[0].eid,
                              cloned.eid)
             self.assertEqual(cloned2.seda_alt_archive_unit_archive_unit_ref_id[0].container[0].eid,
                              cloned2.eid)
 
+    def test_data_object_reference_clone(self):
+        with self.admin_access.repo_cnx() as cnx:
+            transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
+            unit, unit_alt, unit_alt_seq = create_archive_unit(transfer)
+            # don't add link from data object to transfer intentionally to force
+            # going through the archive unit to clone it
+            bdo = create_data_object(unit_alt_seq)
+            cnx.commit()
+
+            clone = cnx.create_entity('SEDAArchiveTransfer', title=u'Clone',
+                                      clone_of=transfer)
+            cnx.commit()
+
+            # Ensure data object is cloned through data_object_reference_id and
+            # container relation is properly handled
+            bdo_clone = cnx.execute('Any MAX(X) WHERE X is SEDABinaryDataObject').one()
+            self.assertNotEqual(bdo_clone.eid, bdo.eid)
+            bdo.cw_clear_all_caches()
+            self.assertEqual([e.eid for e in bdo.container], [transfer.eid])
+            self.assertEqual([e.eid for e in bdo_clone.container], [clone.eid])
+
+            self.failIf(cnx.execute('Any X GROUPBY X WHERE X container C HAVING COUNT(C) > 1'))
+            self.failIf(cnx.execute('Any X WHERE NOT X container C'))
+
 
 class FakeEntity(object):
     cw_etype = 'Whatever'
 
     def __init__(self, _cw):


More information about the saem-devel mailing list