UserType object on wsexpose: 'UuidType' object has no attribute '__name__'

Bug #1265590 reported by Lucas Alvares Gomes
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
WSME
Fix Released
Undecided
Lucas Alvares Gomes

Bug Description

Using an UserType instance with the wsexpose decorator in WSME will fail with:

Traceback (most recent call last):

  File "/usr/local/lib/python2.7/dist-packages/wsmeext/pecan.py", line 73, in callfunction
    pecan.request.body, pecan.request.content_type

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/args.py", line 269, in get_args
    from_args = args_from_args(funcdef, args, kwargs)

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/args.py", line 179, in args_from_args
    "unable to convert to %s" % argdef.datatype.__name__)

AttributeError: 'UuidType' object has no attribute '__name__'

To fix it, the the args_from_args() function at wsme/rest/args.py should check whether the argument type is an object instance of UserType before trying to access it's __name___ attribute.

My new user type Implementation looks like:

class UuidType(wsme.types.UserType):
    """A simple UUID type."""

    basetype = wtypes.text
    name = 'uuid'

    @staticmethod
    def validate(value):
        if not utils.is_uuid_like(value):
            raise exception.InvalidUUID(uuid=value)
        return value

    @staticmethod
    def frombasetype(value):
        return UuidType.validate(value)

uuid_type = UuidType()

On the controller I've something like:

class FakeController(rest.RestController):

    @wsme_pecan.wsexpose(None, uuid_type)
    def get_one(self, obj_uuid):
        ....

I can use my new type as the type of the attributes of my API object class, e.g:

class Object(wsme.types.Base):

    uuid = uuid_type

But I also would like to use it on the wsexpose decorator, just like I do with native types as int, bool etc...

Versions:
pecan (0.4.2)
WSME (0.5b6)

Changed in wsme:
assignee: nobody → Lucas Alvares Gomes (lucasagomes)
Changed in wsme:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to wsme (master)

Reviewed: https://review.openstack.org/64715
Committed: https://git.openstack.org/cgit/stackforge/wsme/commit/?id=228bfbd084ff2c4653740696d26ed10748aaa33c
Submitter: Jenkins
Branch: master

commit 228bfbd084ff2c4653740696d26ed10748aaa33c
Author: Lucas Alvares Gomes <email address hidden>
Date: Thu Jan 2 19:25:45 2014 +0000

    args_from_args() to work with an instance of UserType

    When the args_from_args() function fails to convert a value to a certain
    type it tries to get the name of that type by using the __name__ attribute
    of that type, UserType object instances doesn't have the __name__
    attribute so the function fails when it tries to access it, this patch
    makes WSME to check if it's an UserType instance before getting it's name.

    Change-Id: If78ce0e642997421c97559cc28604421f5c03922
    Closes-Bug: #1265590

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.