--- 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)
--- 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)