Skip to content

allow_unkown in a nested dict field #1163

Description

@mlshapiro

Note this was originally posted as a stack overflow question

Expected Behavior

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. I would expect that I can run the example below:

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)
  • Run the app by running: $ python app.py
  • Test the endpoint with curl:

Pass

$ curl -d '{"data": {"prop": "test prop", "test": 2}}' -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"}

Actual Behavior

  • 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)"}}

Environment

  • Python version:
    • Anaconda Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 12:04:33) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
  • Eve version: 0.8 (installed via pip install eve)

Activity

  1. mlshapiro commented on Jun 11, 2018

    @mlshapiro
    Author

    I was able to get my code working again by adding allow_unknown at the resource level. While this solution works, our goal is to allow unknown properties only at a nested level of the schema. This solution allows data to be submitted with unknown properties to any level of the schema.

    For a little more context, our API point leverages GeoJSON objects, so we want to enable the properties key to allow unknown keys, but not the top level of the GeoJSON object.

  2. added this to the 0.8.1 milestone on Jun 11, 2018
  3. nicolaiarocci commented on Jun 11, 2018

    @nicolaiarocci
    Member

    Hey there, your SO question caught my eye. Fix coming up Real Soon.

  4. mlshapiro commented on Jun 11, 2018

    @mlshapiro
    Author

    Great - Thanks for the help! Really appreciate all the work.

  5. added a commit that references this issue on Mar 24, 2024
    0360bf9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions