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

Extending schema to change properties of existing keys #219

Closed
mprager opened this issue Sep 27, 2016 · 3 comments
Closed

Extending schema to change properties of existing keys #219

mprager opened this issue Sep 27, 2016 · 3 comments

Comments

@mprager
Copy link

mprager commented Sep 27, 2016

Currently modifying key types in an existing schema duplicates the keys and causes all objects to fail validation. Consider this example:

>>> s1 = Schema({Optional('a'): int})
>>> s2 = s1.extend({Required('a'): int})
>>> s1.schema
{'a': <type 'int'>}
>>> s2.schema
{'a': <type 'int'>, 'a': <type 'int'>}

The s2 object now cannot pass validation for any object, since all 'a' keys will be considered for the optional key and the required key appears absent.

>>> s1({})
{}
>>> s1({'a': 3})
{'a': 3}
>>> s2({})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mprager/.virtualenv/validator/lib/python2.7/site-packages/voluptuous/schema_builder.py", line 192, in __call__
    return self._compiled([], data)
  File "/home/mprager/.virtualenv/validator/lib/python2.7/site-packages/voluptuous/schema_builder.py", line 486, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/home/mprager/.virtualenv/validator/lib/python2.7/site-packages/voluptuous/schema_builder.py", line 324, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: required key not provided @ data['a']
>>> s2({'a':4})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mprager/.virtualenv/validator/lib/python2.7/site-packages/voluptuous/schema_builder.py", line 192, in __call__
    return self._compiled([], data)
  File "/home/mprager/.virtualenv/validator/lib/python2.7/site-packages/voluptuous/schema_builder.py", line 486, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/home/mprager/.virtualenv/validator/lib/python2.7/site-packages/voluptuous/schema_builder.py", line 324, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: required key not provided @ data['a']
@tusharmakkar08
Copy link
Collaborator

Hey @mprager

Thanks for pointing out the issue. This looks like a bug in voluptuous. Are you interested in submitting a PR for fixing this ? I can point you to the place where you need to investigate this issue.

Thanks.

@mprager
Copy link
Author

mprager commented Sep 30, 2016

Hey sure thing.

I have some changes I made locally tot he extend function in the Schema
class. They seem to work, I'll pull and submit the changes.

Mike

On Fri, Sep 30, 2016 at 1:18 AM, Tushar Makkar [email protected]
wrote:

Hey @mprager https://github.com/mprager

Thanks for pointing out the issue. This looks like a bug in voluptuous.
Are you interested in submitting a PR for fixing this ? I can point you to
the place where you need to investigate this issue.

Thanks.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#219 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADXXeRRNKC3wiaHDY49vhBcC6LzEQc5Iks5qvJuRgaJpZM4KHzcq
.

@tusharmakkar08
Copy link
Collaborator

Closed via 99fb7bd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants