Passing a string to a nested type fails to json-decode

Bug #1765796 reported by Adam Harwell
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
WSME
Confirmed
Undecided
Unassigned

Bug Description

With a nested type like this:

```
class PoolPOST(BasePoolType):
    name = wtypes.wsattr(wtypes.StringType(max_length=255))
    session_persistence = wtypes.wsattr(SessionPersistencePOST)

class SessionPersistencePOST(types.BaseType):
    type = wtypes.wsattr(wtypes.Enum(str, *constants.SUPPORTED_SP_TYPES),
                         mandatory=True)
    cookie_name = wtypes.wsattr(wtypes.StringType(max_length=255),
                                default=None)
```

If you POST something like this:

```
{
    "name": "hello",
    "session_persistence": ""
}
```

It will explode when trying to decode the subobject as JSON:

```
Traceback (most recent call last):
  File "python3.5/site-packages/wsmeext/pecan.py", line 81, in callfunction
    pecan.request.body, pecan.request.content_type
  File "/usr/lib/python3.5/site-packages/wsme/rest/args.py", line 296, in get_args
    from_body = args_from_body(funcdef, body, mimetype)
  File "python3.5/site-packages/wsme/rest/args.py", line 242, in args_from_body
    body, datatypes, bodyarg=funcdef.body_type is not None
  File "python3.5/site-packages/wsme/rest/json.py", line 266, in parse
    kw = {argname: fromjson(datatypes[argname], jdata)}
  File "python3.5/site-packages/simplegeneric.py", line 63, in dispatch
    return f(*args, **kw)
  File "python3.5/site-packages/wsme/rest/json.py", line 148, in fromjson
    value[attrdef.name])
  File "python3.5/site-packages/simplegeneric.py", line 63, in dispatch
    return f(*args, **kw)
  File "python3.5/site-packages/wsme/rest/json.py", line 148, in fromjson
    value[attrdef.name])
  File "python3.5/site-packages/simplegeneric.py", line 63, in dispatch
    return f(*args, **kw)
  File "python3.5/site-packages/wsme/rest/json.py", line 139, in fromjson
    v_keys = set(value.keys())
AttributeError: 'str' object has no attribute 'keys'
```

Revision history for this message
Adam Harwell (adam-harwell) wrote :

To be clear, I wouldn't expect it to be able to parse this string, but I *would* expect it to fail validation, instead of causing a 500 response.

Changed in wsme:
status: New → Confirmed
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.