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

Proposed by Yann Papouin
Status: Merged
Merged at revision: 4323
Proposed branch: lp:~yann-papouin/ocb-server/6.1-bug-1030795-xmlrpclib-dictkeys-hook
Merge into: lp:ocb-server/6.1
Diff against target: 29 lines (+17/-1)
1 file modified
openerp/wsgi/core.py (+17/-1)
To merge this branch: bzr merge lp:~yann-papouin/ocb-server/6.1-bug-1030795-xmlrpclib-dictkeys-hook
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Raphaël Valyi - http://www.akretion.com Approve
Alexandre Fayolle - camptocamp code review, no test Approve
Review via email: mp+196512@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

LGTM

review: Approve (code review, no test)
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :
review: Approve
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/wsgi/core.py'
2--- openerp/wsgi/core.py 2012-05-30 08:12:58 +0000
3+++ openerp/wsgi/core.py 2013-11-25 10:48:27 +0000
4@@ -75,8 +75,24 @@
5 # RPC_FAULT_CODE_APPLICATION_ERROR value.
6 # This also mimics SimpleXMLRPCDispatcher._marshaled_dispatch() for
7 # exception handling.
8+
9 try:
10- result = openerp.netsvc.dispatch_rpc(service, method, params)
11+ def fix(res):
12+ """
13+ This fix is a minor hook to avoid xmlrpclib to raise TypeError exception:
14+ - To respect the XML-RPC protocol, all "int" and "float" keys must be cast to string to avoid
15+ TypeError, "dictionary key must be string"
16+ - And since "allow_none" is disabled, we replace all None values with a False boolean to avoid
17+ TypeError, "cannot marshal None unless allow_none is enabled"
18+ """
19+ if res is None:
20+ return False
21+ elif type(res) == dict:
22+ return dict((str(key), fix(value)) for key, value in res.items())
23+ else:
24+ return res
25+
26+ result = fix(openerp.netsvc.dispatch_rpc(service, method, params))
27 response = xmlrpclib.dumps((result,), methodresponse=1, allow_none=False, encoding=None)
28 except Exception, e:
29 if legacy_exceptions:

Subscribers

People subscribed via source and target branches

to status/vote changes: