[service] enforce that Service argument and return are json-serialisable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Wed, 26 Jun 2013 13:43:22 +0200
changeset 9094 b151beea9cb6
parent 9093 e2f88df79efd
child 9095 6656fafd96c8
[service] enforce that Service argument and return are json-serialisable The call_service API need to be able to run through RPC. So we ensure front start that it is possible serialise both input and output.
server/session.py
--- a/server/session.py	Tue Jun 25 18:04:08 2013 +0200
+++ b/server/session.py	Wed Jun 26 13:43:22 2013 +0200
@@ -23,6 +23,7 @@
 from time import time
 from uuid import uuid4
 from warnings import warn
+import json
 
 from logilab.common.deprecation import deprecated
 from logilab.common.textutils import unormalize
@@ -1018,11 +1019,20 @@
     # resource accessors ######################################################
 
     def call_service(self, regid, **kwargs):
+        json.dumps(kwargs) # This line ensure that people use serialisable
+                           # argument for call service. this is very important
+                           # to enforce that from start to make sure RPC
+                           # version is available.
         self.info('calling service %s', regid)
         self.set_cnxset()
         try:
             service = self.vreg['services'].select(regid, self, **kwargs)
-            return service.call(**kwargs)
+            result = service.call(**kwargs)
+            json.dumps(result) # This line ensure that service have serialisable
+                               # output. this is very important to enforce that
+                               # from start to make sure RPC version is
+                               # available.
+            return result
         finally:
             self.free_cnxset()