Fix problem with cloning seda_data_object_reference_id
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 12 Dec 2017 18:25:40 +0100
changeset 2924 919faf33df18
parent 2915 451328134bee
child 2925 5af6328d0b3d
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. Requires a yet unreleased fix in the compound cube.
cubicweb_seda/entities/__init__.py
dev-requirements.txt
test/test_entities.py
--- a/cubicweb_seda/entities/__init__.py	Tue Dec 12 17:57:57 2017 +0100
+++ b/cubicweb_seda/entities/__init__.py	Tue Dec 12 18:25:40 2017 +0100
@@ -167,17 +167,15 @@
     __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 (
--- a/dev-requirements.txt	Tue Dec 12 17:57:57 2017 +0100
+++ b/dev-requirements.txt	Tue Dec 12 18:25:40 2017 +0100
@@ -1,1 +1,3 @@
 pytest
+http://hg.logilab.org/review/cubes/compound/archive/tip.tar.bz2#egg=cubicweb-compound
+
--- a/test/test_entities.py	Tue Dec 12 17:57:57 2017 +0100
+++ b/test/test_entities.py	Tue Dec 12 18:25:40 2017 +0100
@@ -1,4 +1,4 @@
-# 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@logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
@@ -166,6 +166,30 @@
             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'