Handle non-subscriptable path in humanize_error#206
Merged
tusharmakkar08 merged 2 commits intoalecthomas:masterfrom Sep 22, 2016
Merged
Handle non-subscriptable path in humanize_error#206tusharmakkar08 merged 2 commits intoalecthomas:masterfrom
tusharmakkar08 merged 2 commits intoalecthomas:masterfrom
Conversation
tusharmakkar08
requested changes
Sep 21, 2016
voluptuous/humanize.py
Outdated
| # The index is not present in the dictionary, list or other indexable | ||
| return None | ||
| except TypeError: # data is not subscriptable | ||
| break |
Contributor
Author
There was a problem hiding this comment.
The advantage of resolving until you hit a failure (by breaking out) is that it helps you in the correct direction.
Happy to comply either way, your call
Collaborator
There was a problem hiding this comment.
Let's keep it consistent with KeyError and IndexError. You can add it in Line 12 and update the comment correspondingly.
tusharmakkar08
approved these changes
Sep 22, 2016
Collaborator
|
@kellerza : Merged 🍰 |
This was referenced Apr 12, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
_nested_getitem currently raises an exception when the error path contains a non-subscriptable entity (e.g. None, int)
This happens in the following situations:
Data to be validated:
{'key1': None}or{'key1': 1}Schema:
vol.Schema('key1': vol.All(ensure_list, [str]))ensure_listmutates the data into an array, if [str] fails the exception contains [0] as an index in the mutated data, but the exception can only be logged using the original (non-list) data, in which case [0] cannot be applied to a non-subscriptable path like int[0] or None[0].