Skip to content

Regression: Allow unknown causes dictionary validation to fail with a KeyError #302

@daviskirk

Description

@daviskirk

Used Cerberus version / latest commit: 1.1


Use-case abstract

Validating a dictionary with allow_unknown set to True


Support request / Bug report

This might be a regression, since testing this on 1.0.1 works fine:

v = cerberus.Validator({'a': {'type': 'dict', 'allow_unknown': True}})
v.validate({'a': {}})

Errors out with the exception:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "./lib/python3.5/site-packages/cerberus/validator.py", line 795, in validate
    self.__normalize_mapping(self.document, self.schema)
  File "./lib/python3.5/site-packages/cerberus/validator.py", line 549, in __normalize_mapping
    self.__normalize_containers(mapping, schema)
  File "./lib/python3.5/site-packages/cerberus/validator.py", line 607, in __normalize_containers
    field, mapping, schema)
  File "./lib/python3.5/site-packages/cerberus/validator.py", line 653, in __normalize_mapping_per_schema
    schema=schema[field]['schema'],
KeyError: 'schema'

The example without the 'allow_unknown' key or with an invalid type work without error:

v = cerberus.Validator({'a': {'type': 'dict'}})
v.validate({'a': {}}) # True
v = cerberus.Validator({'a': {'type': 'dict', 'allow_unknown': True}})
v.validate({})  # True
v.validate({'a': 4})  # False

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions