tiffon · GitHub

#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.

Read the original on github.com ↗