-
Notifications
You must be signed in to change notification settings - Fork 218
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
Handle non-subscriptable path in humanize_error #206
Conversation
@@ -12,6 +12,8 @@ def _nested_getitem(data, path): | |||
except (KeyError, IndexError): | |||
# The index is not present in the dictionary, list or other indexable | |||
return None | |||
except TypeError: # data is not subscriptable | |||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kellerza Shouldn't it return None
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it consistent with KeyError
and IndexError
. You can add it in Line 12 and update the comment correspondingly.
@kellerza : Merged 🍰 |
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_list
mutates 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].