Consider GRAPH_SKIP_RTYPES set for external rdefs as well in iter_all_rdefs
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 10 Apr 2017 16:14:05 +0200
changeset 2615 457b1133267d
parent 2614 964d1e0db292
child 2616 45cae2f412d1
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.
cubicweb_seda/__init__.py
--- a/cubicweb_seda/__init__.py	Mon Apr 10 16:11:08 2017 +0200
+++ b/cubicweb_seda/__init__.py	Mon Apr 10 16:14:05 2017 +0200
@@ -23,7 +23,7 @@
 
 # control of compound graph by adding etype / rtype to the corresponding set below
 GRAPH_SKIP_ETYPES = set()
-GRAPH_SKIP_RTYPES = set()
+GRAPH_SKIP_RTYPES = set(['container'])
 
 
 def seda_profile_container_def(schema):
@@ -32,7 +32,7 @@
                          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).
     """
@@ -51,6 +51,7 @@
     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:
@@ -67,5 +68,5 @@
                 if target not in visited:
                     visited.add(target)
                     stack.append(target)
-        for rdef, role in _iter_external_rdefs(schema[etype]):
+        for rdef, role in _iter_external_rdefs(schema[etype], skip_external_rtypes):
             yield rdef, role