[service] extract session retrieval from "task" closure stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 02 Apr 2013 14:46:13 +0200
branchstable
changeset 8837 f7f4238ffe3c
parent 8831 f7e140182df1
child 8838 27393e484974
[service] extract session retrieval from "task" closure The session was retrieved there because `set_cnxset` must be called in the same thread as the code using it. We now retrieve the session beforehand and explicitly call `set_cnxset`.
server/repository.py
--- a/server/repository.py	Thu Mar 28 15:43:23 2013 +0100
+++ b/server/repository.py	Tue Apr 02 14:46:13 2013 +0200
@@ -882,10 +882,11 @@
         See :class:`cubicweb.dbapi.Connection.call_service`
         and :class:`cubicweb.server.Service`
         """
+        session = self._get_session(sessionid)
         def task():
-            session = self._get_session(sessionid, setcnxset=True)
-            service = session.vreg['services'].select(regid, session, **kwargs)
+            session.set_cnxset()
             try:
+                service = session.vreg['services'].select(regid, session, **kwargs)
                 return service.call(**kwargs)
             finally:
                 session.rollback() # free cnxset