[PATCH 5 of 6 seda V2] Consider GRAPH_SKIP_RTYPES set for external rdefs as well in iter_all_rdefs

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Apr 11 15:22:19 CEST 2017

# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1491833645 -7200
#      Mon Apr 10 16:14:05 2017 +0200
# Node ID 71a5498134904e938440003fdd45913907fe8475
# Parent  f11f715355b5272ab2c8d3e3f07ee6a9e4ccaf8d
Consider GRAPH_SKIP_RTYPES set for external rdefs as well in iter_all_rdefs

giving client cube a consistent way to control graph traversal and so to avoid
considering undesired special relations such as container.

diff --git a/cubicweb_seda/__init__.py b/cubicweb_seda/__init__.py
--- a/cubicweb_seda/__init__.py
+++ b/cubicweb_seda/__init__.py
@@ -21,20 +21,20 @@ Data Exchange Standard for Archival
 from cubicweb_compound import skip_rtypes_set, structure_def, CompositeGraph
 # control of compound graph by adding etype / rtype to the corresponding set below
+GRAPH_SKIP_RTYPES = set(['container'])
 def seda_profile_container_def(schema):
     """Define container for SEDAArchiveTransfer, as a list of (etype, parent_rdefs)."""
     return structure_def(schema, 'SEDAArchiveTransfer',
                          skipetypes=GRAPH_SKIP_ETYPES, skiprtypes=GRAPH_SKIP_RTYPES).items()
-def _iter_external_rdefs(eschema, skip_rtypes=skip_rtypes_set(['container'])):
+def _iter_external_rdefs(eschema, skip_rtypes):
     """Return an iterator on (rdef, role) of external relations from entity schema (i.e.
     non-composite relations).
     for rschema, targets, role in eschema.relation_definitions():
         if rschema in skip_rtypes:
@@ -49,10 +49,11 @@ def _iter_external_rdefs(eschema, skip_r
 def iter_all_rdefs(schema, container_etype):
     """Return an iterator on (rdef, role) of all relations of the compound graph starting from the
     given entity type, both internal (composite) and external (non-composite).
     graph = CompositeGraph(schema, skipetypes=GRAPH_SKIP_ETYPES, skiprtypes=GRAPH_SKIP_RTYPES)
+    skip_external_rtypes = skip_rtypes_set(GRAPH_SKIP_RTYPES)
     stack = [container_etype]
     visited = set(stack)
     while stack:
         etype = stack.pop()
         for (rtype, role), targets in graph.child_relations(etype):
@@ -65,7 +66,7 @@ def iter_all_rdefs(schema, container_ety
                 yield rdef, role
                 if target not in visited:
-        for rdef, role in _iter_external_rdefs(schema[etype]):
+        for rdef, role in _iter_external_rdefs(schema[etype], skip_external_rtypes):
             yield rdef, role

More information about the saem-devel mailing list