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/basecontrollers.py", line 208, in _validate_form
   req.cnx.commit() # ValidationError may be raise on commit
 File "/home/alf/cubicweb/cubicweb/dbapi.py", line 486, in decorator
   return func(self, *args, **kwargs)
 File "/home/alf/cubicweb/cubicweb/dbapi.py", line 691, in commit
   return self._repo.commit(self.sessionid, **self._txid())
 File "/home/alf/cubicweb/cubicweb/server/repository.py", line 794, in commit
   return session.commit()
 File "/home/alf/cubicweb/cubicweb/server/session.py", line 846, in commit
   operation.handle_event('precommit_event')
 File "/home/alf/cubicweb/cubicweb/server/hook.py", line 728, in handle_event
   getattr(self, event)()
 File "/home/alf/cubicweb/cubes/callisto/hooks/case.py", line 56, in precommit_event
   rset = self.session.execute(self.rql, {'case': eid})
 File "/home/alf/cubicweb/cubicweb/server/session.py", line 791, in execute
   rset = self._execute(self, rql, kwargs, build_descr)
 File "/home/alf/cubicweb/cubicweb/server/querier.py", line 731, in execute
   results = plan.execute()
 File "/home/alf/cubicweb/cubicweb/server/querier.py", line 202, in execute
   result = step.execute()
 File "/home/alf/cubicweb/cubicweb/server/ssplanner.py", line 420, in execute
   inputmap)
 File "/home/alf/cubicweb/cubicweb/server/sources/native.py", line 522, in syntax_tree_search
   sql, qargs, cbs = self._rql_sqlgen.generate(union, args, varmap)
 File "/home/alf/cubicweb/cubicweb/server/sources/rql2sql.py", line 737, in generate
   sql = self.union_sql(union)
 File "/home/alf/cubicweb/cubicweb/server/sources/rql2sql.py", line 751, in union_sql
   return self.select_sql(union.children[0], needalias)
 File "/home/alf/cubicweb/cubicweb/server/sources/rql2sql.py", line 833, in select_sql
   needalias or needwrap)
 File "/home/alf/cubicweb/cubicweb/server/sources/rql2sql.py", line 905, in _solutions_sql
   self._state.add_restriction(select.where.accept(self))
 File "<string>", line 1, in <lambda>
 File "/home/alf/cubicweb/cubicweb/server/sources/rql2sql.py", line 958, in visit_and
   part = c.accept(self)
 File "<string>", line 1, in <lambda>
 File "/home/alf/cubicweb/cubicweb/server/sources/rql2sql.py", line 1052, in visit_relation
   sql = self._visit_outer_join_inlined_relation(relation, rschema)
 File "/home/alf/cubicweb/cubicweb/server/sources/rql2sql.py", line 1251, in _visit_outer_join_inlined_relation
   leftalias, rightalias, outertype, '%s=%s' % (lhssql, rhs.accept(self)))
 File "/home/alf/cubicweb/cubicweb/server/sources/rql2sql.py", 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/rql2sql.py", 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.

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