Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defaults don't work in "allow_unknown" schema. #310

Closed
1 task
fomars opened this issue Apr 19, 2017 · 2 comments
Closed
1 task

Defaults don't work in "allow_unknown" schema. #310

fomars opened this issue Apr 19, 2017 · 2 comments
Milestone

Comments

@fomars
Copy link

fomars commented Apr 19, 2017

Used Cerberus version / latest commit: Cerberus==1.1


Use-case abstract

When I use "allow_unknown" property and specify some default in that "unknown" schema and then try to normalize a config, I expect that default to be fulfilled in normalized config.


Support request / Bug report

>>> CORE_SCHEMA = {'version': {'type': 'string'}, 'meta': {'type': 'dict'}}
>>> ALLOW_UNKNOWN_SCHEMA = {
...     'type': 'dict',
...     'schema': {
...             'package': {'type': 'string'},
...             'cfg_path': {'type': 'string', 'default': 'cfg.yaml'}
... }
... }
>>> v = Validator(CORE_SCHEMA, allow_unknown=ALLOW_UNKNOWN_SCHEMA)
>>> CONFIG = {'version': '1.2.3', 'core': {}, 'plugin_foo': {'package': 'foo'}}
>>> v.normalized(CONFIG)
{'core': {}, 'version': '1.2.3', 'plugin_foo': {'package': 'foo'}}
>>> EXPECTED_RESULT = {'version': '1.2.3', 'core': {}, 'plugin_foo': {'package': 'foo', 'cfg_path': 'cfg.yaml'}}


@funkyfuture
Copy link
Member

i pledge to mark this for the 1.2 milestone.

@nicolaiarocci nicolaiarocci added this to the 1.2 milestone Aug 20, 2017
@nicolaiarocci nicolaiarocci modified the milestones: 1.2, 1.3 Mar 26, 2018
@funkyfuture
Copy link
Member

@fomars there's an inconsistency in your use-case as the core field isn't expected to have the defined default included. i'm removing that in the test case.

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants