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

Proposed by Yann Papouin
Status: Merged
Merged at revision: 5210
Proposed branch: lp:~yann-papouin/ocb-server/7.0-bug-1030795-xmlrpclib-dictkeys-hook
Merge into: lp:ocb-server
Diff against target: 27 lines (+16/-1)
1 file modified
openerp/service/wsgi_server.py (+16/-1)
To merge this branch: bzr merge lp:~yann-papouin/ocb-server/7.0-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+196519@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 :

LGTM, no test.
nice contrib!
I used to hack XMLRPC clients to get the things work, now we may see clients that work only with OCB, but hey that's them not enforcing the spec.

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/service/wsgi_server.py'
2--- openerp/service/wsgi_server.py 2013-03-01 12:07:44 +0000
3+++ openerp/service/wsgi_server.py 2013-11-25 11:10:44 +0000
4@@ -79,7 +79,22 @@
5 # This also mimics SimpleXMLRPCDispatcher._marshaled_dispatch() for
6 # exception handling.
7 try:
8- result = openerp.netsvc.dispatch_rpc(service, method, params)
9+ def fix(res):
10+ """
11+ This fix is a minor hook to avoid xmlrpclib to raise TypeError exception:
12+ - To respect the XML-RPC protocol, all "int" and "float" keys must be cast to string to avoid
13+ TypeError, "dictionary key must be string"
14+ - And since "allow_none" is disabled, we replace all None values with a False boolean to avoid
15+ TypeError, "cannot marshal None unless allow_none is enabled"
16+ """
17+ if res is None:
18+ return False
19+ elif type(res) == dict:
20+ return dict((str(key), fix(value)) for key, value in res.items())
21+ else:
22+ return res
23+
24+ result = fix(openerp.netsvc.dispatch_rpc(service, method, params))
25 response = xmlrpclib.dumps((result,), methodresponse=1, allow_none=False, encoding=None)
26 except Exception, e:
27 if legacy_exceptions:

Subscribers

People subscribed via source and target branches

to status/vote changes: