[pyramid] Don't use unsafe_cnx_context_manager for write queries 3.24
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 19 Dec 2016 17:22:48 +0100
branch3.24
changeset 11896 327585fd7670
parent 11895 74e0d1a5560b
child 11901 afd7657a6d65
[pyramid] Don't use unsafe_cnx_context_manager for write queries we may have clumsy error that hide previous problems on attempting to commit the transaction. Closes #16753531
cubicweb/pyramid/session.py
--- a/cubicweb/pyramid/session.py	Wed Dec 14 08:37:11 2016 +0100
+++ b/cubicweb/pyramid/session.py	Mon Dec 19 17:22:48 2016 +0100
@@ -28,6 +28,8 @@
 
     If request has an attached connection, its security will be deactived in the context manager's
     scope, else a new internal connection is returned.
+
+    This should be used for read-only queries, not if you intend to commit/rollback some data.
     """
     cnx = request.cw_cnx
     if cnx is None:
@@ -134,7 +136,7 @@
             data = Binary(pickle.dumps(dict(self)))
             sessioneid = self.sessioneid
 
-            with unsafe_cnx_context_manager(self.request) as cnx:
+            with self.request.registry['cubicweb.repository'].internal_cnx() as cnx:
                 if not sessioneid:
                     session = cnx.create_entity(
                         'CWSession', cwsessiondata=data)