Skip to content

Normalize how objects are converted to text #418

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

Closed
aaugustin opened this issue Oct 18, 2013 · 2 comments
Closed

Normalize how objects are converted to text #418

aaugustin opened this issue Oct 18, 2013 · 2 comments

Comments

@aaugustin
Copy link
Contributor

One of the goals of the Debug Toolbar is to display a meaningful textual representation of a variety of objects.

However, depending on the objects, many things can go wrong. Not all objects implement __unicode__ or __str__. These methods may return a value of the wrong type or raise an exception. Attempting to display the exception may trigger an other exception or an infinite recursion.

(To be honest, the infinite recursion in __unicode__ or __str__ is the worst case I know.)

This ticket proposes to standardize how arbitrary objects are converted to text in an utility function and to use it throughout the project.

django.utils.encoding.force_text could be a good start; however, it's constrained by Django's backwards compatibility requirements and may not have all the features we desire.

@aaugustin
Copy link
Contributor Author

This function, or a sister function, should also handle pretty-printing and indentation. Two issues suggest improving representation of objects in panels: #358 and #371.

@aaugustin
Copy link
Contributor Author

<code>{{ value|pprint }}</code> in the templates seems to work quite well.

Non-ascii characters are escaped eg. \xe9 under Python 2, which is less readable, but not a bad compromise given the variety of crashing bugs we've had in the past.

ryneeverett pushed a commit to ryneeverett/django-debug-toolbar that referenced this issue Oct 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant