# HG changeset patch # User Philippe Pepiot # Date 1555422543 -7200 # Node ID 2508ba96fad28e80c23871a901c495daa75729ee # Parent 8ef162b039a01a8e244f5e0e96e09a177ce396e1 [devtools/testlib] avoid hidding AttributeError in create_user() commit() might raise a AttributeError too. Use getattr(req, 'cnx', req) instead, which is a form already used to get the real cnx in some code: cubicweb/rset.py:577: cnx = getattr(self.req, 'cnx', self.req) cubicweb/schema.py:353: with getattr(_cw, 'cnx', _cw).security_enabled(read=False): We could use if hasattr(req, 'commit') here too but it lead to 3 additionals lines. Maybe we should have commit() and rollback() on cubicweb.web.request.ConnectionCubicWebRequestBase too ? diff -r 8ef162b039a0 -r 2508ba96fad2 cubicweb/devtools/testlib.py --- a/cubicweb/devtools/testlib.py Fri Apr 05 17:40:02 2019 +0200 +++ b/cubicweb/devtools/testlib.py Tue Apr 16 15:49:03 2019 +0200 @@ -479,10 +479,7 @@ reverse_primary_email=user) user.cw_clear_relation_cache('in_group', 'subject') if commit: - try: - req.commit() # req is a session - except AttributeError: - req.cnx.commit() + getattr(req, 'cnx', req).commit() return user # other utilities #########################################################