[PATCH 2 of 2 compound v2] Add follow_relations to cw_skip_copy_for

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Dec 14 07:59:34 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1513098573 -3600
#      Tue Dec 12 18:09:33 2017 +0100
# Node ID 465a0e927e27018cb46a225c67aae864ff0e201e
# Parent  0fc9b87651095ba0773fe2b623c05d525e564676
Add follow_relations to cw_skip_copy_for

When one add some non-composite relation to be followed, it should be
automatically added to cw_skip_copy_for else it will be both deep copied and
swallow copied, as demonstrated by the amended test.

diff --git a/cubicweb_compound/entities.py b/cubicweb_compound/entities.py
--- a/cubicweb_compound/entities.py
+++ b/cubicweb_compound/entities.py
@@ -231,10 +231,13 @@ class IClonableAdapter(EntityAdapter):
     def skip_swallow_copy_for(self):
         return set(chain(
             # turn skiprtypes into a list suitable for Entity.cw_skip_copy_for
             ((rtype, 'subject') for rtype in self.skiprtypes),
             ((rtype, 'object') for rtype in self.skiprtypes),
+            # also, relations that should be considered for cloning
+            # shouldn't be also swallow copied
+            self.follow_relations,
         ))
 
 
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__)
diff --git a/test/test_compound.py b/test/test_compound.py
--- a/test/test_compound.py
+++ b/test/test_compound.py
@@ -350,10 +350,13 @@ class CloneTC(CubicWebTC):
                 ' NOT G identity OG',
                 {'og': group.eid})
             self.assertEqual(len(rset), 1)
             self.assertEqual(clone.reverse_member[0].eid, rset[0][0])
 
+            group = cnx.entity_from_eid(group.eid)
+            self.assertEqual(len(group.member), 1)
+
     def test_clone_skiprtypes(self):
         with self.admin_access.repo_cnx() as cnx:
             bob = cnx.create_entity('Agent', name=u'bob')
             cnx.create_entity('Group', member=bob)
             cnx.commit()


More information about the saem-devel mailing list