Don't rollback if exception is HTTPSuccessful or HTTPRedirection
authorChristophe de Vienne <christophe@unlish.com>
Sat, 08 Nov 2014 23:07:20 +0100
changeset 11524 54c83bfda277
parent 11523 8c80344b119e
child 11525 5eb4e27e9998
Don't rollback if exception is HTTPSuccessful or HTTPRedirection In the request finishing, the 'cleanup' callback set by _cw_cnx automatically commit the transaction except is an exception is set on the request. Problem is, redirections and successul http return code can raise exceptions. This patch detects such exceptions and avoid rolling back the transaction. Closes #4566482
pyramid_cubicweb/core.py
--- a/pyramid_cubicweb/core.py	Thu Nov 06 22:26:16 2014 +0100
+++ b/pyramid_cubicweb/core.py	Sat Nov 08 23:07:20 2014 +0100
@@ -138,7 +138,10 @@
     cnx = repoapi.ClientConnection(request.cw_session)
 
     def cleanup(request):
-        if request.exception is not None:
+        if (request.exception is not None and not isinstance(
+            request.exception, (
+                httpexceptions.HTTPSuccessful,
+                httpexceptions.HTTPRedirection))):
             cnx.rollback()
         else:
             cnx.commit()