[PATCH 4 of 5 seda] 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:12:33 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 1cd617d62c1e23b8872cc422fde8b7d40943a9bc
# Parent  7791fde1c736869f0bc18d67e2d56f2f9475459e
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