# HG changeset patch # User Christophe de Vienne # Date 1431077887 -7200 # Node ID a9940c6cd693e93b7d0aadedf1c1e49b9b41243a # Parent 4f8aa5fcd5da44144352953b513411b5cb1ad6c8 Rollback 'uncommitable' cnx Closes #5343870 diff -r 4f8aa5fcd5da -r a9940c6cd693 pyramid_cubicweb/core.py --- a/pyramid_cubicweb/core.py Wed Apr 29 13:09:06 2015 +0200 +++ b/pyramid_cubicweb/core.py Fri May 08 11:38:07 2015 +0200 @@ -248,6 +248,8 @@ httpexceptions.HTTPSuccessful, httpexceptions.HTTPRedirection))): cnx.rollback() + elif cnx._cnx.commit_state == 'uncommitable': + cnx.rollback() else: cnx.commit() cnx.__exit__(None, None, None) diff -r 4f8aa5fcd5da -r a9940c6cd693 pyramid_cubicweb/tests/test_core.py --- a/pyramid_cubicweb/tests/test_core.py Wed Apr 29 13:09:06 2015 +0200 +++ b/pyramid_cubicweb/tests/test_core.py Fri May 08 11:38:07 2015 +0200 @@ -2,6 +2,7 @@ from cubicweb.view import View from cubicweb.web import Redirect +from cubicweb import ValidationError class Redirector(View): @@ -12,9 +13,22 @@ raise Redirect('http://example.org') +def put_in_uncommitable_state(request): + try: + request.cw_cnx.execute('SET U login NULL WHERE U login "anon"') + except ValidationError: + pass + request.response.body = 'OK' + return request.response + + class CoreTest(PyramidCWTest): anonymous_allowed = True + def includeme(self, config): + config.add_route('uncommitable', '/uncommitable') + config.add_view(put_in_uncommitable_state, route_name='uncommitable') + def test_cw_to_pyramid_copy_headers_on_redirect(self): self.vreg.register(Redirector) try: @@ -23,3 +37,8 @@ self.assertEqual(res.headers['Cache-Control'], 'no-cache') finally: self.vreg.unregister(Redirector) + + def test_uncommitable_cnx(self): + res = self.webapp.get('/uncommitable') + self.assertEqual(res.text, 'OK') + self.assertEqual(res.status_int, 200)