check that non final variable are not used as rhs of an attribute relation
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 19 May 2011 09:39:37 +0200
changeset 628 e1c5a48f2afd
parent 627 baf0543aa7d3
child 629 e7e1fc35bad5
check that non final variable are not used as rhs of an attribute relation
stcheck.py
test/unittest_stcheck.py
--- a/stcheck.py	Wed May 18 15:28:34 2011 +0200
+++ b/stcheck.py	Thu May 19 09:39:37 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2004-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2004-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of rql.
@@ -665,6 +665,9 @@
                 update_attrvars(var, relation, lhs)
 
 def update_attrvars(var, relation, lhs):
+    if var.stinfo['relations'] - var.stinfo['rhsrelations']:
+        raise BadRQLQuery('variable %s should not be used as rhs of attribute relation %s'
+                          % (var.name, relation))
     # stinfo['attrvars'] is set of couple (lhs variable name, relation name)
     # where the `var` attribute variable is used
     lhsvar = getattr(lhs, 'variable', None)
--- a/test/unittest_stcheck.py	Wed May 18 15:28:34 2011 +0200
+++ b/test/unittest_stcheck.py	Thu May 19 09:39:37 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2004-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2004-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of rql.
@@ -313,5 +313,10 @@
         self.failUnless(C.scope is rqlst.with_[0].query.children[0], C.scope)
         self.assertEqual(len(C.stinfo['relations']), 2)
 
+    def test_no_attr_var_if_uid_rel(self):
+        with self.assertRaises(BadRQLQuery) as cm:
+            self.parse('Any X, Y WHERE X work_for Z, Y work_for Z, X eid > Y')
+        self.assertEqual(str(cm.exception), 'variable Y should not be used as rhs of attribute relation X eid > Y')
+
 if __name__ == '__main__':
     unittest_main()