cubicweb #1784285 [rql2sql] crash when using a relation for inner and outer join [resolved]

the following query crashes rql2sql conversion:

rql = ('Any CASE, CALIBCFG, CFG '
       'WHERE CASE eid %(case)s, CFG in_case CASE, '
       '      CFG is Configuration, '
       '      CALIBCFG is CalibrationConfig, CALIBCFG? in_case CASE')

The schema is straightforward: Configuration and CalibrationConfig both have a 1* relation 'in_case' to the Case entity. The in_case relation is composite='object' and inlined=True.

The stack trace is

Traceback (most recent call last):
 File "/home/alf/cubicweb/cubicweb/web/views/", line 208, in _validate_form
   req.cnx.commit() # ValidationError may be raise on commit
 File "/home/alf/cubicweb/cubicweb/", line 486, in decorator
   return func(self, *args, **kwargs)
 File "/home/alf/cubicweb/cubicweb/", line 691, in commit
   return self._repo.commit(self.sessionid, **self._txid())
 File "/home/alf/cubicweb/cubicweb/server/", line 794, in commit
   return session.commit()
 File "/home/alf/cubicweb/cubicweb/server/", line 846, in commit
 File "/home/alf/cubicweb/cubicweb/server/", line 728, in handle_event
   getattr(self, event)()
 File "/home/alf/cubicweb/cubes/callisto/hooks/", line 56, in precommit_event
   rset = self.session.execute(self.rql, {'case': eid})
 File "/home/alf/cubicweb/cubicweb/server/", line 791, in execute
   rset = self._execute(self, rql, kwargs, build_descr)
 File "/home/alf/cubicweb/cubicweb/server/", line 731, in execute
   results = plan.execute()
 File "/home/alf/cubicweb/cubicweb/server/", line 202, in execute
   result = step.execute()
 File "/home/alf/cubicweb/cubicweb/server/", line 420, in execute
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 522, in syntax_tree_search
   sql, qargs, cbs = self._rql_sqlgen.generate(union, args, varmap)
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 737, in generate
   sql = self.union_sql(union)
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 751, in union_sql
   return self.select_sql(union.children[0], needalias)
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 833, in select_sql
   needalias or needwrap)
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 905, in _solutions_sql
 File "<string>", line 1, in <lambda>
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 958, in visit_and
   part = c.accept(self)
 File "<string>", line 1, in <lambda>
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 1052, in visit_relation
   sql = self._visit_outer_join_inlined_relation(relation, rschema)
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 1251, in _visit_outer_join_inlined_relation
   leftalias, rightalias, outertype, '%s=%s' % (lhssql, rhs.accept(self)))
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 560, in replace_tables_by_outer_join
   self.mark_as_used_in_outer_join(leftalias, addpending=False)
 File "/home/alf/cubicweb/cubicweb/server/sources/", line 524, in mark_as_used_in_outer_join
   scope, tabledef = self.tables[tablealias]
KeyError: None

I investigated a bit from the outside:

  • if I change the outer join on CALIBCFG to an inner join, no crash
  • if I remove the part of the query concerning CFG, no crash

so it seems that using in_case both as an inner and an outer join causes problem. Not sure if the fact that the relation is inlined matters.

I'm using CW 3.12.8, with rql 0.29.

done in3.12.10
load left0.000
closed by#f4b954676721 closes #1784285: [rql2sql] crash when using a relation for inner and outer join