[querier] fix eid relations handling in SET queries (closes #2797052) oldstable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 08 Apr 2013 11:09:50 +0200
brancholdstable
changeset 8853 f61755c05c89
parent 8507 0c111b232927
child 8854 0ff798f80138
[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.
server/ssplanner.py
server/test/unittest_querier.py
--- a/server/ssplanner.py	Wed Aug 01 10:30:48 2012 +0200
+++ b/server/ssplanner.py	Mon Apr 08 11:09:50 2013 +0200
@@ -79,7 +79,12 @@
     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))
--- a/server/test/unittest_querier.py	Wed Aug 01 10:30:48 2012 +0200
+++ b/server/test/unittest_querier.py	Mon Apr 08 11:09:50 2013 +0200
@@ -1517,5 +1517,28 @@
             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()