[req] raise KeyError instead of AssertionError in req.find()
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Wed, 26 Apr 2017 15:04:40 +0200
changeset 12182 50109859da43
parent 12181 29dae4b0332a
child 12183 af5d0a3c3f1a
[req] raise KeyError instead of AssertionError in req.find()
cubicweb/req.py
cubicweb/test/unittest_req.py
--- a/cubicweb/req.py	Tue Apr 25 17:31:24 2017 +0200
+++ b/cubicweb/req.py	Wed Apr 26 15:04:40 2017 +0200
@@ -224,13 +224,13 @@
                 kwargs[attr] = value.eid
             if attr.startswith('reverse_'):
                 attr = attr[8:]
-                assert attr in eschema.objrels, \
-                    '{0} not in {1} object relations'.format(attr, eschema)
+                if attr not in eschema.objrels:
+                    raise KeyError('{0} not in {1} object relations'.format(attr, eschema))
                 parts.append('{var} {attr} X, {var} eid %(reverse_{attr})s'.format(
                     var=next(varmaker), attr=attr))
             else:
-                assert attr in eschema.subjrels, \
-                    '{0} not in {1} subject relations'.format(attr, eschema)
+                if attr not in eschema.subjrels:
+                    raise KeyError('{0} not in {1} subject relations'.format(attr, eschema))
                 parts.append('X {attr} %({attr})s'.format(attr=attr))
 
         rql = ', '.join(parts)
--- a/cubicweb/test/unittest_req.py	Tue Apr 25 17:31:24 2017 +0200
+++ b/cubicweb/test/unittest_req.py	Wed Apr 26 15:04:40 2017 +0200
@@ -148,12 +148,12 @@
             self.assertEqual(len(users), 2)
 
             with self.assertRaisesRegexp(
-                AssertionError, '^chapeau not in CWUser subject relations$'
+                KeyError, "^'chapeau not in CWUser subject relations'$"
             ):
                 req.find('CWUser', chapeau=u"melon")
 
             with self.assertRaisesRegexp(
-                AssertionError, '^buddy not in CWUser object relations$'
+                KeyError, "^'buddy not in CWUser object relations'$"
             ):
                 req.find('CWUser', reverse_buddy=users[0])