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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Copy link

ssergiienko commented Feb 20, 2015

+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

This comment has been minimized.

Copy link
Member

nicolaiarocci commented Mar 12, 2015

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

nicolaiarocci added a commit that referenced this issue Mar 12, 2015

@ssergiienko

This comment has been minimized.

Copy link

ssergiienko commented Mar 22, 2015

@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

This comment has been minimized.

Copy link
Member

nicolaiarocci commented Mar 22, 2015

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