XMLRPC can't handle non-strings as keys

Bug #689575 reported by Nick White
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Won't Fix
Undecided
Unassigned

Bug Description

I recently came across the problem described at http://www.openerp.com/forum/post22813.html - namely that several functions return dictionaries of the format {id1: result1, id2: result2}.

When accessing these functions through XMLRPC (at least using python's xmlrpclib), the use of integer ids as keys causes an error. For example, the following code snippet (using get_product_available from addons/stock/product.py):

stocknum = sock.execute(db, uid, pass, 'product.product', 'get_product_available', p['id'], {'location': stockid})

Results in the traceback:

  File "/usr/lib/python2.6/xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.6/xmlrpclib.py", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1392, in _parse_response
    return u.close()
  File "/usr/lib/python2.6/xmlrpclib.py", line 838, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: "<type 'exceptions.TypeError'>:dictionary key must be string">

I'm not very experienced with XMLRPC, so apologies if this is a problem specific to python's xmlrpclib, or my use of it.

But if not, then perhaps a solution similar to the last patch proposed on the above forum post - ensuring dict keys are run through str() - would be wise.

This is with OpenERP 5 rev. 2159.

Revision history for this message
xrg (xrg) wrote : Re: [Bug 689575] [NEW] XMLRPC can't handle non-strings as keys

On Monday 13 December 2010, you wrote:
> Public bug reported:
>
> I recently came across the problem described at
> http://www.openerp.com/forum/post22813.html - namely that several
> functions return dictionaries of the format {id1: result1, id2:
> result2}.

> I'm not very experienced with XMLRPC, so apologies if this is a problem
> specific to python's xmlrpclib, or my use of it.
>

That's a limitation of the XML-RPC library. We can't really do much about it,
as we don't want to redefine the protocols.
This is the reason, too, that we craft the result of some ORM functions, so
that they fit this limitation

Revision history for this message
Azazahmed Saiyed (OpenERP) (saz-openerp) wrote :

Hello,

I do agree with the xrg. This is the limitation of XML-RPC library of python. So this will not be under the scanner of open-erp framework. For the sake of clarity in launchpad i am closing this bug.

Thanks.

Changed in openobject-server:
status: New → Won't Fix
Revision history for this message
Nick White (r-launchpad-njw-me-uk) wrote :

Ah, OK. I wasn't sure from xrg's explanation whether the limitation was with the protocol or xmlrpclib's implementation of it. I see now it's the latter (though to be fair, the spec described at http://www.xmlrpc.com/spec isn't too specific).

Thanks for your help.

Revision history for this message
Nick White (r-launchpad-njw-me-uk) wrote :

For posterity, this behaviour of xmlrpclib is documented and intended: from http://docs.python.org/library/xmlrpclib.html

"Structures: A Python dictionary. Keys must be strings, values may be any conformable type. Objects of user-defined classes can be passed in; only their __dict__ attribute is transmitted."

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

If this is a xmlrpclib limitation, and OpenERP relies on xmlrpclib, shouldn't OpenERP wrap the calls to xmlrpclib in a way that makes sure this does not happen?: I mean, replacing the keys of the returned dictionaries with their string representation.

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

By the way, seems that in Tryton they did something similar of what I was proposing: http://hg2.tryton.org/trytond/rev/b578f95ef5c7

Revision history for this message
Raimon Esteve (www.zikzakmedia.com) (resteve) wrote :

Nice comment Borja: Tryton! ;)

If we use Pyro Protocol (need install pyro module), you can try call this function and work fine. I get this error XML-RPC protocol but not by Pyro.

 context = { 'states': ('done',), 'what': ('in', 'out') }
 result = proxy.dispatch( 'object', 'execute', dbname, uid, pwd, 'product.product', 'get_product_available', [product.id], context)

See you.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.