#18063: repr() should return only ascii, not unicode
-------------------------------------+-------------------------------------
Reporter: guettli | Owner: nobody
Type: Bug | Status: reopened
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Release blocker | Triage Stage:
Keywords: | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kmtracey):
* status: closed => reopened
* resolution: fixed =>
* severity: Normal => Release blocker
* stage: Accepted => Unreviewed
Comment:
I don't believe this fix is correct. More broadly, the problem description
is not correct. Nowhere in the referenced Python documentation
(http://docs.python.org/reference/datamodel.html?highlight=repr#object.__repr!__)
does it say the (byte)string returned by `__repr__` must contain only
ASCII characters. Django was not returning unicode from `__repr__`, it was
returning a utf-8 encoded bytestring. That's perfectly legal Python. The
fact that some other bits of Python tools are unhelpful and deal with non-
ascii data by throwing up "unprintable exception object" when an exception
is raised involving a model instance with non-ASCII data in its repr
indicates a bug somewhere else. That bug should be fixed at its source,
not by removing non-ASCII characters from model instances' repr.
The referenced doc also states "This is typically used for debugging, so
it is important that the representation is information-rich and
unambiguous." This change has moved in the wrong direction on that score.
Consider before the change:
{{{
--> ./manage.py shell
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django
>>> django.get_version()
u'1.5.dev20120819181059'
>>> from ctrac.models import Cat
>>> Cat.objects.filter(adopted_name__startswith='Am')
[<Cat: Skittle (now Amélie)>]
>>> quit()
}}}
After the change:
{{{
--> ./manage.py shell
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django
>>> django.get_version()
u'1.5.dev20120821213816'
>>> from ctrac.models import Cat
>>> Cat.objects.filter(adopted_name__startswith='Am')
[<Cat: Skittle (now Am?lie)>]
>>>
}}}
That second output would have me concerned the my data been corrupted,
when in fact it has not. It is just `__repr__` that is now corrupting it
on output.
I believe this change should be reverted and the ticket closed either
wontfix or needsinfo. needsinfo would be to investigate under what
conditions the real problem (unprintable exception objects) occurs and to
see if there is anything that Django is doing to cause it (though I rather
suspect is a base Python problem).
Marking release blocker because this has introduced a regression in
functionality from previous release.
--
Ticket URL: <https://code.djangoproject.com/ticket/18063#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.