Simple built-in types are not converted from string in json

Bug #1450544 reported by Stéphane Bisinger
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
WSME
Fix Released
Undecided
Stéphane Bisinger

Bug Description

If I define a function with a built-in type as an argument, the argument is not converted in the correct built-in, but it is passed as is in the REST protocol. So, for instance, a method like this could fail:

class MyService(WSRoot):
  @expose(int)
  @validate(int)
  def add(self, value):
    return value + 2

If called with this curl like this:

curl -H "Content-Type: application/json" -X POST -d '{"value": " 3"}' http://localhost/wsme/myservice/add

WSME should either return an HTTP 400 status code (because we require an int, but got a string), or try to convert the string to int, only returning a 400 status code if the convertion fails

This is the case for all basic built-in types (bool, int, long, float)

Changed in wsme:
assignee: nobody → Stéphane Bisinger (kjir)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to wsme (master)

Reviewed: https://review.openstack.org/179839
Committed: https://git.openstack.org/cgit/stackforge/wsme/commit/?id=9a0d3c1461c272567653defdfec1c3680939dbdb
Submitter: Jenkins
Branch: master

commit 9a0d3c1461c272567653defdfec1c3680939dbdb
Author: Stéphane Bisinger <email address hidden>
Date: Mon May 4 18:41:32 2015 +0200

    Convert built-in types when passed as strings

    If on a service exposed with some arguments with a built-in type among
    int, long, bool or float a request is made passing a JSON with string
    values instead of the intended type, the called function would have
    strings as parameters instead of the expected types. This also means
    that invalid strings would still be passed without error, leading to
    unexpected failures. This patch tries to convert the string to the
    intended type before failing with an InvalidInput exception if the
    string can't be converted. This is to try and be as nice as possible
    with whatever input is thrown at wsme.

    Closes-Bug: 1450544
    Change-Id: I705c183bb68457d539074b78ce81339b9464e1e0

Changed in wsme:
status: In Progress → Fix Committed
Changed in wsme:
milestone: none → 0.8.0
status: Fix Committed → Fix Released
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.