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

Empty lists behaving incorrectly #397

Closed
ChristopherChudzicki opened this issue Jun 27, 2019 · 1 comment · Fixed by #434
Closed

Empty lists behaving incorrectly #397

ChristopherChudzicki opened this issue Jun 27, 2019 · 1 comment · Fixed by #434

Comments

@ChristopherChudzicki
Copy link

We're in the process of upgrading from version 0.10.5 to version 0.11.5, and empty list validation is now giving strange errors:

from voluptuous import Schema, Required, MultipleInvalid

schema = Schema({
    Required('variables', default=[]): []
})

try:
    schema({'variables': ['x']})
except MultipleInvalid as error:
    print(error)
# in 0.10.5: not a valid value for dictionary value @ data['variables']
# in 0.11.5: not a valid value for dictionary value @ data['x']

The error message doesn't make sense to me...there is no dictionary with key 'x'.

ChristopherChudzicki added a commit to ChristopherChudzicki/mitx-grading-library that referenced this issue Jun 27, 2019
Mostly these have to do with validation of default inputs.

Also, alecthomas/voluptuous#397, which I assume is a bug
@alecthomas
Copy link
Owner

That seems like a bug.

monopolis added a commit to monopolis/voluptuous that referenced this issue Oct 12, 2020
The behaviour seems to have been introduced in commit
95489bd that modified the schema of an empty list in order
to provide a consistent behaviour between Schema({}) and Schema([]).

The commit introduced an enumeration of the incorrect values rather
than the expected behaviour of showing the key with the incorrect
value.

This commit provides the expected behaviour, and is also consistent
with the 'pathless' behaviour currently implemented, meaning that

- Schema([])([1]) -> 'not a valid value @ data[1]'
- Schema({'key': []})({'key': [1]) -> 'not a valid dictionary value @
data['key'].

Finally, as new unit test is provided to ensure that the new behaviour
remains intact.
@spacegaier spacegaier linked a pull request Dec 6, 2020 that will close this issue
spacegaier pushed a commit that referenced this issue Dec 6, 2020
* Add ability to use custom flags when running tox

.. so that you can e.g. run `tox -- --pdb` to get a debugger
on test failures.

* Remove value enumeration when validating empty list (#397)

The behaviour seems to have been introduced in commit
95489bd that modified the schema of an empty list in order
to provide a consistent behaviour between Schema({}) and Schema([]).

The commit introduced an enumeration of the incorrect values rather
than the expected behaviour of showing the key with the incorrect
value.

This commit provides the expected behaviour, and is also consistent
with the 'pathless' behaviour currently implemented, meaning that

- Schema([])([1]) -> 'not a valid value @ data[1]'
- Schema({'key': []})({'key': [1]) -> 'not a valid dictionary value @
data['key'].

Finally, as new unit test is provided to ensure that the new behaviour
remains intact.
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

Successfully merging a pull request may close this issue.

2 participants