Have purge_unknown and allow_unknown play nice together
See original GitHub issueIssue
(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}}
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@audricschiltknecht please submit a PR for this. Make sure the docs are updated, maybe with the very same example you posted here, so users know what the intended behavior is.
I’ve just created a PR. However, I could not run doc creation nor doctests because of an error raised by sphinx (neither using my virtualenv nor by running the docker script).