# HG changeset patch # User Sylvain Thénault <sylvain.thenault@logilab.fr> # Date 1305790777 -7200 # Thu May 19 09:39:37 2011 +0200 # Node ID e1c5a48f2afd3c49d1fd72f0276249f651710f59 # Parent baf0543aa7d3dbbedf55fa95c40e125a8e6b2dc6 check that non final variable are not used as rhs of an attribute relation diff --git a/stcheck.py b/stcheck.py --- a/stcheck.py +++ b/stcheck.py @@ -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) diff --git a/test/unittest_stcheck.py b/test/unittest_stcheck.py --- a/test/unittest_stcheck.py +++ b/test/unittest_stcheck.py @@ -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()