[core] adjust cnx handling for cubicweb 3.21
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 25 Jun 2015 09:51:32 +0200
changeset 11580 e8f8a211e503
parent 11579 78ba3e88a549
child 11581 5b30fd6f18c4
[core] adjust cnx handling for cubicweb 3.21 Closes #5731814
pyramid_cubicweb/core.py
--- a/pyramid_cubicweb/core.py	Tue Jun 30 11:15:03 2015 +0200
+++ b/pyramid_cubicweb/core.py	Thu Jun 25 09:51:32 2015 +0200
@@ -243,19 +243,21 @@
     session = request.cw_session
     if session is None:
         return None
-    cnx = repoapi.ClientConnection(session)
+    cnx = session.new_cnx()
 
     def cleanup(request):
-        if (request.exception is not None and not isinstance(
-            request.exception, (
-                httpexceptions.HTTPSuccessful,
-                httpexceptions.HTTPRedirection))):
-            cnx.rollback()
-        elif cnx._cnx.commit_state == 'uncommitable':
-            cnx.rollback()
-        else:
-            cnx.commit()
-        cnx.__exit__(None, None, None)
+        try:
+            if (request.exception is not None and not isinstance(
+                request.exception, (
+                    httpexceptions.HTTPSuccessful,
+                    httpexceptions.HTTPRedirection))):
+                cnx.rollback()
+            elif cnx.commit_state == 'uncommitable':
+                cnx.rollback()
+            else:
+                cnx.commit()
+        finally:
+            cnx.__exit__(None, None, None)
 
     request.add_finished_callback(cleanup)
     cnx.__enter__()