[core] Adjust cw<3.21 compatibility
Most of cubibweb < 3.21 expects a ClientConnection as the main connection.
Related to #5731814
Closes #5878592
--- 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()