Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer fails when array of types is in schema #1112

Closed
Kobzol opened this issue Feb 14, 2018 · 1 comment
Closed

Serializer fails when array of types is in schema #1112

Kobzol opened this issue Feb 14, 2018 · 1 comment
Labels
Milestone

Comments

@Kobzol
Copy link

Kobzol commented Feb 14, 2018

When an array of types is used in a schema ('type': ['string', 'number']), the Eve serializer (the function serialize in common.py) will fail with the exception 'unhashable list'. This can be hard to find, because the serializer swallows exceptions and sometimes the request will go through OK, but sometimes it will fail because the serializer didn't serialize everything correctly.

Example (the exception is thrown with this schema at common.py:423):

{
    'val': {
        'type': 'dict',
        'schema': {
            'x': {
                'type': ['string', 'number'],
                'required': True
            },
            'timestamp': {
                'type': 'datetime',
                'required': False
            }
        }
    }
}

When I POST a new item to this schema, it will either insert it and return 201 or return 422 with the error "timestamp": "must be of datetime type". This depends on the order in which the serializer goes through the fields, which is non-deterministic. Either it serializes the datetime first, then it's ok, or it finds the constraint 'type': ['string', 'number'] which stops the serializer, the datetime stays unparsed and the request fails.

Is array of types supported by Eve? It is officially supported by Cerberus. I tried replacing it with 'anyof_type': ['string', 'number'], but that returns an error (no definitions validate).

Version: 0.8-dev from latest github master (commit sha 1d4a308)
Python version: happens both on 2.7 and 3.5

@nicolaiarocci nicolaiarocci added this to the 0.8.1 milestone May 17, 2018
@nicolaiarocci
Copy link
Member

This should be fixed now. Thanks and sorry for the long wait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants