diff --git a/stcheck.py b/stcheck.py
index baf0543aa7d3dbbedf55fa95c40e125a8e6b2dc6_c3RjaGVjay5weQ==..e1c5a48f2afd3c49d1fd72f0276249f651710f59_c3RjaGVjay5weQ== 100644
--- 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
index baf0543aa7d3dbbedf55fa95c40e125a8e6b2dc6_dGVzdC91bml0dGVzdF9zdGNoZWNrLnB5..e1c5a48f2afd3c49d1fd72f0276249f651710f59_dGVzdC91bml0dGVzdF9zdGNoZWNrLnB5 100644
--- 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()