-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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 substitution errors with no parameters to ValidationError #9313
Conversation
…alidationError messages. "%" substitution requires all keys to be matched during substitution, so if a ValidationError happens to include a %(foo)s style variable not met by parameters, it will throw a KeyError. In Field.run_validators there is also an accumulation of errors that are wrapped by a final ValidationError which can then throw TypeError if any of the sub-errors contain replaceable substrings. This patch implements a subclassed dict which simply returns the key's name for any missing keys. The end result for the logic in exceptions.py is that the final message is an exact copy of the original message with only found parameters replaced and the rest left untouched. Signed-off-by: James Tanner <[email protected]>
fb4d18c
to
93b677c
Compare
Signed-off-by: James Tanner <[email protected]>
Signed-off-by: James Tanner <[email protected]>
Signed-off-by: James Tanner <[email protected]>
Signed-off-by: James Tanner <[email protected]>
Signed-off-by: James Tanner <[email protected]>
Signed-off-by: James Tanner <[email protected]>
Signed-off-by: James Tanner <[email protected]>
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.
Catching these errors will unblock us from being able to upgrade. In the cases where the format errors, it is almost always the case that params
is empty dict, so raising the error with the detail
matches the expectation.
I'm not yet convinced by this... I'd suggest we instead revert #8863 as a first pass. The equivalent case in Django uses |
This is obsolete now that #9326 is merged, which I fully support. If someone re-attempts the feature in the future, please feel free to copy/paste the unit tests I made in this PR. |
%
substituation requires all keys to be matched during substitution, so if a ValidationError happens to include a%(foo)s
style variable not met by the parameters, it will throw a KeyError. In Field.run_validators there is also an accumulation of errors that are wrapped by a final ValidationError which can then throw TypeError if any of the sub-errors contain replaceable substrings.This is more complicated than it first seemed. #9295 has a dateformat string throwing a ValueError, which won't ever work with
foo % bar
so this patch needs more testing and edge case handling.This patch implements a new function to handle the string substitution and related errors in a unified way that returns the original string if something fails.
should fix #9295