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

v0.8 'allow_unknown" validation rule fails with nested dict fields #1165

Closed
nicolaiarocci opened this issue Jun 11, 2018 · 1 comment
Closed
Labels
Milestone

Comments

@nicolaiarocci
Copy link
Member

nicolaiarocci commented Jun 11, 2018

As reported on Stack Overflow, and verified locally by me:


We developed a API using Eve 0.7 that used allow_unknown on a nested dict field. This field worked as expected according to the cerberus documentation.

We are now upgrading to Eve 0.8 and our endpoints no longer respect the allow_unknown parameter in nested dicts.

Example

settings.py

DOMAIN = {
    'endpoint': {
        'schema': {
            'data': {
                'type': 'dict',
                'allow_unknown': True,
                'schema': {
                    'prop': {'type': 'string'}
                }
            }
        }
    }
}

RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE']

app.py

from eve import Eve

app = Eve()
app.run(debug=True)

Test

  • Run the app by running: $ python app.py
  • Test the endpoint with curl:

Pass

$ curl -d '{"data": {"prop": "test prop"}}' -H 'Content-Type: application/json'  http://127.0.0.1:5000/endpoint
{"_updated": "Fri, 08 Jun 2018 19:43:11 GMT", "_created": "Fri, 08 Jun 2018 19:43:11 GMT", "_etag": "e04dd19a6e13c74ccdb5561722bb001b0f5dff28", "_id": "5b1adc4f198a2527650320a4", "_links": {"self": {"title": "Endpoint", "href": "endpoint/5b1adc4f198a2527650320a4"}}, "_status": "OK"}

Fail (would expect this to pass)

$ curl -d '{"data": {"prop": "test prop", "test": 2}}' -H 'Content-Type: application/json'  http://127.0.0.1:5000/endpoint
{"_status": "ERR", "_issues": {"data": {"test": "unknown field"}}, "_error": {"code": 422, "message": "Insertion failure: 1 document(s) contain(s) error(s)"}}
@nicolaiarocci nicolaiarocci added this to the 0.8.1 milestone Jun 11, 2018
@nicolaiarocci
Copy link
Member Author

Dupe, see #1163

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

1 participant