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

allow_unknown does not apply to sub-dictionaries in a list #67

Closed
tiffon opened this issue Feb 10, 2015 · 4 comments
Closed

allow_unknown does not apply to sub-dictionaries in a list #67

tiffon opened this issue Feb 10, 2015 · 4 comments

Comments

@tiffon
Copy link

tiffon commented Feb 10, 2015

#40 doesn't seem to apply when the sub-dictionary is in a list.

To reproduce:

import cerberus
cerberus.__version__
# '0.8'
v = cerberus.Validator(allow_unknown=True)
schema = {
    'a_dict': {
        'type': 'dict',
        'schema': {
            'address': {'type': 'string'},
            'city': {'type': 'string', 'required': True}
        }
    }
}
document = {
    'a_dict': {
        'address': 'my address',
        'city': 'my town',
        'extra': True
    }
}
v.validate(document, schema)
# True
schema_w_list = {
    'list_o_dicts': {
        'type': 'list',
        'minlength': 1,
        'schema': {
            'type': 'dict',
            'schema': {
                'address': {'type': 'string'},
                'city': {'type': 'string', 'required': True}
            }
        }
    }
}
document_w_list = {
    'list_o_dicts': [{
        'address': 'my address',
        'city': 'my town',
        'extra': True
    }]
}
v.validate(document_w_list, schema_w_list)
# False
v.errors
# {'list_o_dicts': {0: {'extra': 'unknown field'}}}

On a side-note, cerberus is awesome.

@ssergiienko
Copy link

+1 to fix this bug. Maybe "allowed_unknown" should be configurable separately per each scheme like this:

schema = {
    'a_dict': {
        'type': 'dict',
        'allowed_unknown': True,
        'schema': {
            'address': {'type': 'string'},
            'city': {'type': 'string', 'required': True}
        }
    }
}

Except for this cerberus is awesome)

@nicolaiarocci
Copy link
Member

Hey guys, thanks for reporting this one. Should be fixed now.

@ssergiienko
Copy link

@nicolaiarocci , thanks for fix! What do you think about my idea of implement allowed_unknown on schema level? It can be pretty usefull... is it hard to implement?

@nicolaiarocci
Copy link
Member

Could you open a separate ticket for that? Thanks!

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

No branches or pull requests

3 participants