[PATCH 1 of 7 saem_ref V2] [seda] Configure the seda compound tree to stop considering Activity

Sylvain Thenault sylvain.thenault at logilab.fr
Mon Apr 10 14:50:41 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490876699 -7200
#      Thu Mar 30 14:24:59 2017 +0200
# Node ID b8599a52fa6dd09ce1b4457840a9ecb3179a1eb5
# Parent  fe766631d60a999d4d7338169a3404bacdb23cd1
[seda] Configure the seda compound tree to stop considering Activity

We've already fixed permission issues from the same problem (Activity being
added by saem_ref and in several compound trees). Now, it appears that 'used'
and 'generated' relations appear in the SEDA_PARENT_RTYPES structure of
seda's hooks, leading to a container relation being set for activities even when
they belong to a scheme, concept or authority record, even though this relation
doesn't exists in the schema. This causes later problem, such has being unable
to remove those entities (hence the non regression test).

Instead of simply fixing SEDA_PARENT_RTYPES, make the seda compound tree
configurable and skip activity once for all so we may expect no more problems
because of this.

A migration script is added to cleanup the 'container' relation by removing all
records where subject of the relation is one of the AuthorityRecord, ConceptSchema
and Concept types (only SEDA* types should have the container relation). This
is done using SQL and not RQL since those records can't even exist according to
the schema.

diff --git a/cubicweb_saem_ref/migration/0.15.1_Any.py b/cubicweb_saem_ref/migration/0.15.1_Any.py
--- a/cubicweb_saem_ref/migration/0.15.1_Any.py
+++ b/cubicweb_saem_ref/migration/0.15.1_Any.py
@@ -1,2 +1,8 @@
 for ertype in ('generated', 'used', 'associated_with', 'place_address'):
     sync_schema_props_perms(ertype)
+
+
+sql("DELETE FROM container_relation WHERE EXISTS("
+    "SELECT FROM entities WHERE eid_to=eid AND "
+    "type IN ('AuthorityRecord', 'ConceptScheme', 'Concept'))")
+commit()
diff --git a/cubicweb_saem_ref/site_cubicweb.py b/cubicweb_saem_ref/site_cubicweb.py
--- a/cubicweb_saem_ref/site_cubicweb.py
+++ b/cubicweb_saem_ref/site_cubicweb.py
@@ -27,11 +27,12 @@ from cubicweb.uilib import PRINTERS
 from cubicweb.entity import Entity
 from cubicweb.web import request
 
 from cubes.skos import rdfio
 from cubes.skos.ccplugin import ImportSkosData
-from cubicweb_seda import dataimport as seda
+import cubicweb_seda as seda
+import cubicweb_seda.dataimport as seda_dataimport
 
 from . import permanent_url, _massive_store_factory, _nohook_store_factory
 
 # this import is needed to take account of pg_trgm monkeypatches
 # while executing cubicweb-ctl commands (db-rebuild-fti)
@@ -133,11 +134,11 @@ def init_seda_scheme(cnx, title, _count=
         try:
             ark = u'25651/v%s' % ark_hack[title]
         except KeyError:
             pass
     scheme = cnx.create_entity('ConceptScheme', title=title, description=description, ark=ark)
-    seda.EXTID2EID_CACHE['ark:/' + ark] = scheme.eid
+    seda_dataimport.EXTID2EID_CACHE['ark:/' + ark] = scheme.eid
     return scheme
 
 
 @monkeypatch(seda)
 def get_store(cnx):
@@ -149,10 +150,16 @@ def get_store(cnx):
     else:
         from cubicweb.dataimport.stores import NoHookRQLObjectStore
         return NoHookRQLObjectStore(cnx, metagen=metagen)
 
 
+# configure seda compound graph to discard Activity and its relations, else it causes problem
+# because it belongs to several graphs with different compound implementation (using "container"
+# relation or not)
+seda.GRAPH_SKIP_ETYPES.add('Activity')
+
+
 ####################################################################################################
 # temporary monkey-patches #########################################################################
 ####################################################################################################
 
 from yams.constraints import Attribute, BoundaryConstraint, cstr_json_loads  # noqa
diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,3 +1,4 @@
 mock
 pytest
 webtest
+http://hg.logilab.org/review/cubes/seda/archive/tip.tar.bz2#egg=cubicweb-seda
diff --git a/test/unittest_hooks.py b/test/unittest_hooks.py
--- a/test/unittest_hooks.py
+++ b/test/unittest_hooks.py
@@ -483,10 +483,19 @@ class EntityLifeCycleTC(CubicWebTC):
             transfer.cw_set(title=u'123')
             cnx.commit()
             self._check_modification(cnx, transfer.eid,
                                      'modified title')
 
+    def test_nonregr_concept_container(self):
+        with self.new_access(u'bob').repo_cnx() as cnx:
+            scheme = cnx.create_entity('ConceptScheme', title=u'my thesaurus',
+                                       ark_naa=testutils.naa(cnx))
+            concept = scheme.add_concept(u'hello')
+            cnx.commit()
+            concept.cw_delete()
+            cnx.commit()
+
 
 class SEDAArchiveTransferHooksTC(CubicWebTC):
 
     def test_profile_deprecated(self):
         """Test hook deprecating a SEDA Profile upon successor publication."""


More information about the saem-devel mailing list