Ladon can't understand primitive bool

Bug #990826 reported by Carlos Jenkins Pérez
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ladon
Fix Committed
High
jsgaarde

Bug Description

Ladon 0.7.0 is unable to understand bool primitive as parameter of a function:

********************* services.py
from ladon.ladonizer import ladonize

class Services(object):

    @ladonize(bool, rtype=unicode)
    def do_something(self, foo):
        if foo:
            return u'Yes!'
        return u'No!'

********************* client.py
from ladon.clients.jsonwsp import JSONWSPClient

service = JSONWSPClient('http://localhost:8080/Services/jsonwsp/description')
print service.do_something(foo=True).response_dict
print service.do_something(foo=False).response_dict

********************* Output (two times)
{u'fault': {u'detail': [u'Traceback (most recent call last):', u' File "/usr/local/lib/python2.7/dist-packages/ladon/server/dispatcher.py", line 142, in dispatch_request', u' result = self.call_method(method,req_dict,tc,export_dict)', u' File "/usr/local/lib/python2.7/dist-packages/ladon/server/dispatcher.py", line 73, in call_method', u" args += [tc.from_unicode_string(val,arg['type'])]", u' File "/usr/local/lib/python2.7/dist-packages/ladon/types/typeconverter.py", line 36, in from_unicode_string', u' raise NonUnicodeError(type(val))', u"NonUnicodeError: Values mut be unicode while converting from string to Ladon supported types: encountered <type 'bool'>", u''], u'code': u'server', u'lineno': 149, u'string': u"Values mut be unicode while converting from string to Ladon supported types: encountered <type 'bool'>", u'filename': u'dispatcher'}, u'version': u'1.0', u'type': u'jsonwsp/fault'}

The relevant part is at line 36 in /usr/local/lib/python2.7/dist-packages/ladon/types/typeconverter.py:

                # Check the value type
                if not type(val) == PORTABLE_STRING:
                        raise NonUnicodeError(type(val))

But val is bool.

Kind regards

Revision history for this message
jsgaarde (jakob-simon-gaarde) wrote :

Hi Carlos.

Unfortunately this is not a Ladon bug - it seems that the "loads" function in the standard module "json" has a bug (Python 2.7). Using the "parse_constant" keyword seems to have no effect at all.

I have reported the problem: http://bugs.python.org/issue14692

/ Jakob

Changed in ladon:
assignee: nobody → jsgaarde (jakob-simon-gaarde)
status: New → In Progress
Revision history for this message
jsgaarde (jakob-simon-gaarde) wrote :

I have created a fix for this bug.
/ Jakob

Changed in ladon:
status: In Progress → Fix Committed
importance: Undecided → High
Revision history for this message
Carlos Jenkins Pérez (carlos.jenkins) wrote : Re: [Bug 990826] Re: Ladon can't understand primitive bool

Thank you very much Jakob, really appreciated.

The workarround I'm using is:

print service.do_something(foo=str(True)).response_dict

The interface haven't changed, it seem that if the boolean is converted to
str first Ladon will nevertheless undestand it as boolean.

Kind regards

--
Carlos Jenkins
http://carlos.jenkins.co.cr/

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.