[PATCH 3 of 3 saem] [entities] Don't copy activities on clone

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


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1513153645 -3600
#      Wed Dec 13 09:27:25 2017 +0100
# Node ID 17740642a454e7c8236395626bd8ada7b8559a53
# Parent  d29e9194daad16f4a916e93563815a5297dd4758
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 17740642a454
[entities] Don't copy activities on clone

In that purpose add `used` and `generated` relation to the clone adapter's
skiprtypes, skipping 'Actvity' entity types isn't enough (may need more
exploration to understand why and if this is desired...).

diff --git a/cubicweb_saem_ref/entities/seda.py b/cubicweb_saem_ref/entities/seda.py
--- a/cubicweb_saem_ref/entities/seda.py
+++ b/cubicweb_saem_ref/entities/seda.py
@@ -55,11 +55,11 @@ def agency_id(self, agency):
     return None if agency.agency is None else 'ark:/' + agency.agency.ark
 
 
 SEDAArchiveTransferIClonableAdapter.__select__ &= is_in_state('published')
 SEDAArchiveTransferIClonableAdapter.rtype = 'new_version_of'
-SEDAArchiveTransferIClonableAdapter.skiprtypes += ('clone_of',)
+SEDAArchiveTransferIClonableAdapter.skiprtypes += ('clone_of', 'used', 'generated')
 
 
 class SEDAArchiveTransfer(SEDAArchiveTransfer):
     SEDAArchiveTransfer.fetch_attrs.append('ark')
 
diff --git a/test/unittest_entities_container.py b/test/unittest_entities_container.py
--- a/test/unittest_entities_container.py
+++ b/test/unittest_entities_container.py
@@ -101,10 +101,15 @@ class TreeTC(CubicWebTC):
             # have been copied (but other parts of the test live in the seda
             # cube)
             self.assertEqual(clone.ark_naa[0].eid, transfer.ark_naa[0].eid)
             self.assertEqual(len(clone.reverse_use_profile), 0)
 
+            # Ensure activites are not copied
+            self.assertEqual(len(clone.reverse_generated), 1)
+            self.assertEqual(len(clone.reverse_used), 1)
+            self.assertNotEqual(clone.reverse_used[0].start, transfer.reverse_used[-1].start)
+
             # 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()


More information about the saem-devel mailing list