← Back to team overview

openerp-community-reviewer team mailing list archive

lp:~yann-papouin/ocb-server/6.1-bug-1030795-xmlrpclib-dictkeys-hook into lp:ocb-server/6.1

 

Yann Papouin has proposed merging lp:~yann-papouin/ocb-server/6.1-bug-1030795-xmlrpclib-dictkeys-hook into lp:ocb-server/6.1.

Requested reviews:
  OpenERP Community Backports Team (ocb)
Related bugs:
  Bug #1030795 in OpenERP Community Backports (Server): "stock_picking.action_invoice_create:  calling by xmlrpc raises TypeError"
  https://bugs.launchpad.net/ocb-server/+bug/1030795
  Bug #1249355 in OpenERP Server: "XML-RPC  object service tries to return non-XML-RPC conformant replies"
  https://bugs.launchpad.net/openobject-server/+bug/1249355

For more details, see:
https://code.launchpad.net/~yann-papouin/ocb-server/6.1-bug-1030795-xmlrpclib-dictkeys-hook/+merge/196512
-- 
https://code.launchpad.net/~yann-papouin/ocb-server/6.1-bug-1030795-xmlrpclib-dictkeys-hook/+merge/196512
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~yann-papouin/ocb-server/6.1-bug-1030795-xmlrpclib-dictkeys-hook into lp:ocb-server/6.1.
=== modified file 'openerp/wsgi/core.py'
--- openerp/wsgi/core.py	2012-05-30 08:12:58 +0000
+++ openerp/wsgi/core.py	2013-11-25 10:48:27 +0000
@@ -75,8 +75,24 @@
     # RPC_FAULT_CODE_APPLICATION_ERROR value.
     # This also mimics SimpleXMLRPCDispatcher._marshaled_dispatch() for
     # exception handling.
+        
     try:
-        result = openerp.netsvc.dispatch_rpc(service, method, params)
+        def fix(res):
+            """
+            This fix is a minor hook to avoid xmlrpclib to raise TypeError exception: 
+            - To respect the XML-RPC protocol, all "int" and "float" keys must be cast to string to avoid
+              TypeError, "dictionary key must be string"
+            - And since "allow_none" is disabled, we replace all None values with a False boolean to avoid
+              TypeError, "cannot marshal None unless allow_none is enabled"
+            """
+            if res is None:
+                return False
+            elif type(res) == dict:
+                return dict((str(key), fix(value)) for key, value in res.items())
+            else:
+                return res
+            
+        result = fix(openerp.netsvc.dispatch_rpc(service, method, params))
         response = xmlrpclib.dumps((result,), methodresponse=1, allow_none=False, encoding=None)
     except Exception, e:
         if legacy_exceptions:


Follow ups