Commit f365f845 authored by Adrien Di Mascio's avatar Adrien Di Mascio
Browse files

[querier] fix eid relations handling in SET queries (closes #2797052)

_extract_eid_consts() implementation must consider arithmetic operators
when trying to associate rql variables to specific eids.

--HG--
branch : oldstable
parent 0c111b232927
......@@ -79,7 +79,12 @@ def _extract_eid_consts(plan, rqlst):
checkread = session.read_security
eschema = session.vreg.schema.eschema
for rel in rqlst.where.get_nodes(Relation):
if rel.r_type == 'eid' and not rel.neged(strict=True):
# only care for 'eid' relations ...
if (rel.r_type == 'eid'
# ... that are not part of a NOT clause ...
and not rel.neged(strict=True)
# ... and where eid is specified by '=' operator.
and rel.children[1].operator == '='):
lhs, rhs = rel.get_variable_parts()
if isinstance(rhs, Constant):
eid = typed_eid(rhs.eval(plan.args))
......
......@@ -1517,5 +1517,28 @@ class NonRegressionTC(CubicWebTC):
res = self.execute('Any X WHERE X has_text %(text)s', {'text': 'aff2'})
self.assertEqual(res.rows, [[aff2.eid]])
def test_set_relations_eid(self):
req = self.request()
# create 3 email addresses
a1 = req.create_entity('EmailAddress', address=u'a1')
a2 = req.create_entity('EmailAddress', address=u'a2')
a3 = req.create_entity('EmailAddress', address=u'a3')
# SET relations using '>=' operator on eids
req.execute('SET U use_email A WHERE U login "admin", A eid >= %s' % a2.eid)
self.assertEqual(
[[a2.eid], [a3.eid]],
req.execute('Any A ORDERBY A WHERE U use_email A, U login "admin"').rows)
# DELETE
req.execute('DELETE U use_email A WHERE U login "admin", A eid > %s' % a2.eid)
self.assertEqual(
[[a2.eid]],
req.execute('Any A ORDERBY A WHERE U use_email A, U login "admin"').rows)
req.execute('DELETE U use_email A WHERE U login "admin"')
# SET relations using '<' operator on eids
req.execute('SET U use_email A WHERE U login "admin", A eid < %s' % a2.eid)
self.assertEqual(
[[a1.eid]],
req.execute('Any A ORDERBY A WHERE U use_email A, U login "admin"').rows)
if __name__ == '__main__':
unittest_main()
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