Commit 0934c62b authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[querier] Allow usage of computed relation into WHERE clause of write queries

This used to crash because of an attempt to access unexisting  table.

Closes #17113286

--HG--
branch : 3.25
parent 6ab1793f6f83
......@@ -24,7 +24,7 @@ from rql.nodes import Constant, Relation
from cubicweb import QueryError
from cubicweb.schema import VIRTUAL_RTYPES
from cubicweb.rqlrewrite import add_types_restriction
from cubicweb.rqlrewrite import add_types_restriction, RQLRelationRewriter
from cubicweb.server.edition import EditedEntity
READ_ONLY_RTYPES = set(('eid', 'has_text', 'is', 'is_instance_of', 'identity'))
......@@ -296,6 +296,9 @@ class SSPlanner(object):
union.append(select)
select.clean_solutions(solutions)
add_types_restriction(self.schema, select)
# Rewrite computed relations
rewriter = RQLRelationRewriter(plan.cnx)
rewriter.rewrite(union, plan.args)
self.rqlhelper.annotate(union)
return self.build_select_plan(plan, union)
......
......@@ -1399,6 +1399,16 @@ Any P1,B,E WHERE P1 identity P2 WITH
self.assertEqual(len(rset.rows), 1)
self.assertEqual(rset.description, [('CWUser',)])
# computed relation tests ##################################################
def test_computed_relation_write_queries(self):
"""Ensure we can use computed relation in WHERE clause of write queries"""
with self.admin_access.cnx() as cnx:
cnx.execute('INSERT Personne P: P nom "user", P login_user U WHERE NOT U user_login P')
cnx.execute('DELETE P login_user U WHERE U user_login P')
cnx.execute('DELETE Personne P WHERE U user_login P')
cnx.execute('SET U login "people" WHERE U user_login P')
# ZT datetime tests ########################################################
def test_tz_datetime(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment