[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 10 Dec 2014 10:49:07 +0100
changeset 10180 ea10572fccfe
parent 10179 a328b91938b2
child 10181 215403b9798f
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253 Avoid a KeyError.
rset.py
test/unittest_rset.py
--- a/rset.py	Thu Dec 04 11:37:10 2014 +0100
+++ b/rset.py	Wed Dec 10 10:49:07 2014 +0100
@@ -520,6 +520,7 @@
     def _rset_structure(self, eschema, entity_col):
         eid_col = col = entity_col
         rqlst = self.syntax_tree()
+        get_rschema = eschema.schema.rschema
         attr_cols = {}
         rel_cols = {}
         if rqlst.TYPE == 'select':
@@ -531,10 +532,7 @@
         # take care, due to outer join support, we may find None
         # values for non final relation
         for i, attr, role in attr_desc_iterator(select, col, entity_col):
-            if role == 'subject':
-                rschema = eschema.subjrels[attr]
-            else:
-                rschema = eschema.objrels[attr]
+            rschema = get_rschema(attr)
             if rschema.final:
                 if attr == 'eid':
                     eid_col = i
--- a/test/unittest_rset.py	Thu Dec 04 11:37:10 2014 +0100
+++ b/test/unittest_rset.py	Wed Dec 10 10:49:07 2014 +0100
@@ -563,6 +563,14 @@
             self.assertIsInstance(str(rset), basestring)
             self.assertEqual(len(str(rset).splitlines()), 1)
 
+    def test_nonregr_symmetric_relation(self):
+        # see https://www.cubicweb.org/ticket/4739253
+        with self.admin_access.client_cnx() as cnx:
+            p1 = cnx.create_entity('Personne', nom=u'sylvain')
+            cnx.create_entity('Personne', nom=u'denis', connait=p1)
+            cnx.commit()
+            rset = cnx.execute('Any X,Y WHERE X connait Y')
+            rset.get_entity(0, 1) # used to raise KeyError
 
 if __name__ == '__main__':
     unittest_main()