-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix django unicode error #2217
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
base: main
Are you sure you want to change the base?
Fix django unicode error #2217
Conversation
for more information, see https://pre-commit.ci
…ebug-toolbar into fix-django-unicode-error
def catch_force_errors(force_function, value): | ||
try: | ||
return force_function(value) | ||
except DjangoUnicodeDecodeError: | ||
return "Debug toolbar was unable to parse value" |
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.
There are a few places we use force_str
and I suspect we may want to swap all of them out with this new function. Perhaps we should create a sanitize.py
file and put this in there with a doc string explaining the interface and what it does. Then use that everywhere we've been using force_str
. I'd consider keeping the name as force_str
too, but that's just my preference. We'd want to have an explicit test covering the functionality of this new function too.
There are some other sanitizing functions in utils.py
that can be moved over too, though that should be a separate commit. Or I can do that.
try: | ||
return force_function(value) | ||
except DjangoUnicodeDecodeError: | ||
return "Debug toolbar was unable to parse value" |
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.
return "Debug toolbar was unable to parse value" | |
return "Django Debug Toolbar was unable to parse value." |
nitpick: We use the full name in other messaging presented to users.
* Fixed force_str to catch error and give out default string if value is not | ||
serializable. |
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.
* Fixed force_str to catch error and give out default string if value is not | |
serializable. | |
* Updated logic that forces values to strings to render "Django Debug Toolbar was | |
unable to parse value." when there's a decoding error. |
I think we're better off trying to communicate what is going to change from a developer experience here rather than what technically changed. A user may try to figure out why they are getting this message and our documentation may not explain it. Having it here in the change log will help them realize it's intentional and be able to track what the issue/PR is to see why it was changed.
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.
Thank you @jmgutu for putting this together quickly. I think there are a few changes we should make to improve the toolbar as a whole and to make the developer experience a bit better. Please let me know if you think differently.
Description
The force serialize function in [django-debug-toolbar/debug_toolbar/panels/settings.py] was throwing errors for values that are not serializable. The proposed solution returns the serialized value if the value is serializable or returns 'Debug toolbar was unable to parse value'
Fixes #2172
Checklist:
docs/changes.rst
.