cubicweb #3661918 KeyError in rqlrewrite with ? in query [validation pending]

In some application, the following query Any ST,COUNT(R) GROUPBY ST WHERE ST is ProcessingStudy, R is Run, R? in_study ST leads to a KeyError in rqlrewrite:

Traceback (most recent call last)
  File "/home/dlaxalde/src/simulagora/logilab/common/testlib.py", line 664, in _proceed
    testfunc(*args, **kwargs)
  File "/home/dlaxalde/src/simulagora/cubes/sccp_base/test/unittest_views.py", line 73, in test_study_table
    'Any ST,COUNT(R) GROUPBY ST '
  File "/home/dlaxalde/src/simulagora/cubes/sccp_base/test/unittest_views.py", line 50, in process
    plan.preprocess(union)
  File "/home/dlaxalde/src/simulagora/cubicweb/server/querier.py", line 231, in preprocess
    noinvariant = self._insert_security(union)
  File "/home/dlaxalde/src/simulagora/cubicweb/server/querier.py", line 251, in _insert_security
    select, self.args, localchecks, restricted, noinvariant)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 329, in insert_local_checks
    self.rewrite(myrqlst, lcheckdef, kwargs)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 354, in rewrite
    self.insert_snippets(snippets)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 382, in insert_snippets
    self.insert_varmap_snippets(varmap, rqlexprs, varexistsmap)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 407, in insert_varmap_snippets
    subselect.solutions, self.kwargs)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 354, in rewrite
    self.insert_snippets(snippets)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 382, in insert_snippets
    self.insert_varmap_snippets(varmap, rqlexprs, varexistsmap)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 426, in insert_varmap_snippets
    new = self.insert_snippet(varmap, rqlexpr.snippet_rqlst, previous)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 444, in insert_snippet
    new = snippetrqlst.where.accept(self)
  File "/home/dlaxalde/src/simulagora/rql/utils.py", line 166, in accept
    return visit_method(self, *args, **kwargs)
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 802, in visit_relation
    if not self.keep_var(lhs.name):
  File "/home/dlaxalde/src/simulagora/cubicweb/rqlrewrite.py", line 792, in keep_var
    if has_path(vargraph, varname, existingvar):
  File "/home/dlaxalde/src/simulagora/logilab/common/graph.py", line 271, in has_path
    for destnode in graph_dict[fromnode]:
KeyError: 'X'

Read permissions are customized for Run entity type (ERQLExpression(EXISTS(X in_processingstudy C2), EXISTS(X owned_by U))) and ProcessingStudy (ERQLExpression('X public TRUE'))

prioritynormal
typebug
done in3.18.4
load left0.000
closed by#48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
patch[rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph [applied]