pyramid_cubicweb/core.py
changeset 11589 7079ba70c2a7
parent 11580 e8f8a211e503
child 11622 308ac9def79f
--- a/pyramid_cubicweb/core.py	Fri Jul 24 14:21:13 2015 +0200
+++ b/pyramid_cubicweb/core.py	Fri Jul 24 16:59:13 2015 +0200
@@ -22,6 +22,9 @@
 log = logging.getLogger(__name__)
 
 
+CW_321 = cubicweb.__pkginfo__.numversion >= (3, 21, 0)
+
+
 class Connection(cwsession.Connection):
     """ A specialised Connection that access the session data through a
     property.
@@ -243,7 +246,17 @@
     session = request.cw_session
     if session is None:
         return None
-    cnx = session.new_cnx()
+
+    if CW_321:
+        cnx = session.new_cnx()
+
+        def commit_state(cnx):
+            return cnx.commit_state
+    else:
+        cnx = repoapi.ClientConnection(session)
+
+        def commit_state(cnx):
+            return cnx._cnx.commit_state
 
     def cleanup(request):
         try:
@@ -252,7 +265,7 @@
                     httpexceptions.HTTPSuccessful,
                     httpexceptions.HTTPRedirection))):
                 cnx.rollback()
-            elif cnx.commit_state == 'uncommitable':
+            elif commit_state(cnx) == 'uncommitable':
                 cnx.rollback()
             else:
                 cnx.commit()