audricschiltknecht · GitHub

Issue

(Unless I am missing something)
Setting purge_unknown on Validator (or top-level schemas) will ignore specific allow_unknown properties on fields.

The use-case is that while undeclared fields should be purged from the document, there are some of the sub-documents that have been explicitly tagged as permitting unknown fields, and these should not be purged.

Reproduce

  • First example
>>> validator = Validator(purge_unknown=True)
>>> schema = {'foo': {'type': 'dict', 'allow_unknown': True}}
>>> document = {'foo': {'bar': True}, 'bar': 'foo'}
>>> validator.validated(document, schema)
{'foo': {}}

Expected:

{'foo': {'bar': True}}
  • Second example
validator = Validator(purge_unknown=True)
schema = {'foo': {'type': 'dict', 'schema': {'bar': {'type': 'string'}}, 'allow_unknown': True}}
document = {'foo': {'bar': 'baz', 'corge': False}, 'thud': 'xyzzy'}
>>> validator.validated(document, schema)
{'foo': {'bar': 'baz'}}

Expected:

{'foo': {'bar': 'baz', 'corge': False}}

Read the original on github.com ↗