question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have purge_unknown and allow_unknown play nice together

See original GitHub issue

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}}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolaiaroccicommented, Jul 22, 2017

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

0reactions
audricschiltknechtcommented, Jul 25, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found