Do not set uidrel if RHS of the relation is not a constant.

Closes #9441457

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset824af70cc527
branchdefault
phasepublic
hiddenno
parent revision#20785e2a102c make add_type_restriction accept a list of entity types
child revision#71d2371d75e6 Start test using py.test, #1efe574ab302 [pkg] Add python-logilab-constraint to debian dependencies
files modified by this revision
rql/stcheck.py
test/unittest_stcheck.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1480630758 -3600
# Thu Dec 01 23:19:18 2016 +0100
# Node ID 824af70cc527444d624293d8c02bdc2ad894bda6
# Parent 20785e2a102c91f900e33c63227dd81fbf581d9a
Do not set uidrel if RHS of the relation is not a constant.

Closes #9441457

diff --git a/rql/stcheck.py b/rql/stcheck.py
@@ -681,11 +681,12 @@
1                              # + check variable's scope
2                              isinstance(relation.parent, Not) or
3                              relation.parent.ored()):
4                          if isinstance(constnode, Constant):
5                              lhsvar.stinfo['constnode'] = constnode
6 -                        lhsvar.stinfo['uidrel'] = relation
7 +                        if not isinstance(constnode, VariableRef):
8 +                            lhsvar.stinfo['uidrel'] = relation
9                  else:
10                      lhsvar.stinfo.setdefault(key, set()).add(relation)
11              elif rschema.final or rschema.inlined:
12                  bloc_simplification(lhsvar, relation)
13          for vref in rhs.get_nodes(VariableRef):
diff --git a/test/unittest_stcheck.py b/test/unittest_stcheck.py
@@ -321,7 +321,14 @@
14      def test_no_attr_var_if_uid_rel(self):
15          with self.assertRaises(BadRQLQuery) as cm:
16              self.parse('Any X, Y WHERE X work_for Z, Y work_for Z, X eid > Y')
17          self.assertEqual(str(cm.exception), 'variable Y should not be used as rhs of attribute relation X eid > Y')
18 
19 +    def test_no_uid_rel_if_not_constant(self):
20 +        rqlst = self.parse('Any X,EID WHERE X eid EID').children[0]
21 +        self.assertEqual(rqlst.defined_vars['X'].stinfo['uidrel'], None)
22 +        rqlst = self.parse('Any X WHERE X eid IN (1,2,3)').children[0]
23 +        self.assertTrue(rqlst.defined_vars['X'].stinfo['uidrel'])
24 +
25 +
26  if __name__ == '__main__':
27      unittest_main()