[core] Adjust cw<3.21 compatibility
authorChristophe de Vienne <christophe@unlish.com>
Fri, 24 Jul 2015 16:59:13 +0200
changeset 11589 7079ba70c2a7
parent 11588 50e1fda83837
child 11590 398b2c840e14
[core] Adjust cw<3.21 compatibility Most of cubibweb < 3.21 expects a ClientConnection as the main connection. Related to #5731814 Closes #5878592
pyramid_cubicweb/core.py
--- 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()