[service] handle cnxset in the async case only stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 02 Apr 2013 15:11:21 +0200
branchstable
changeset 8838 27393e484974
parent 8837 f7f4238ffe3c
child 8839 49eb84b80b96
[service] handle cnxset in the async case only The service may be called by a session, we really do not want the call to service to mess with the transaction state. This does not apply to async were thread magic ensure a dedicated transaction.
server/repository.py
--- a/server/repository.py	Tue Apr 02 14:46:13 2013 +0200
+++ b/server/repository.py	Tue Apr 02 15:11:21 2013 +0200
@@ -883,19 +883,20 @@
         and :class:`cubicweb.server.Service`
         """
         session = self._get_session(sessionid)
-        def task():
-            session.set_cnxset()
-            try:
-                service = session.vreg['services'].select(regid, session, **kwargs)
-                return service.call(**kwargs)
-            finally:
-                session.rollback() # free cnxset
         if async:
             self.info('calling service %s asynchronously', regid)
+            def task():
+                session.set_cnxset()
+                try:
+                    service = session.vreg['services'].select(regid, session, **kwargs)
+                    return service.call(**kwargs)
+                finally:
+                    session.rollback() # free cnxset
             self.threaded_task(task)
         else:
             self.info('calling service %s synchronously', regid)
-            return task()
+            service = session.vreg['services'].select(regid, session, **kwargs)
+            return service.call(**kwargs)
 
     def user_info(self, sessionid, props=None):
         """this method should be used by client to: