#25730: base.Model __str__ sometimes returns unicode on Python 2
-------------------------------------+-------------------------------------
     Reporter:  keturn               |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by charettes):

 * status:  closed => new
 * type:  Bug => Cleanup/optimization
 * version:  1.8 => master
 * resolution:  worksforme =>
 * stage:  Unreviewed => Accepted


Comment:

 Ahh I think I see what you mean by unicode string returned.

 The default `__str__` implementation returns `'%s object' %
 self.__class__.__name__` if `hasattr(self, '__unicode__')`.

 This isn't really an issue because `self.__class__.__name__` can only
 contain ASCII characters on Python 2 and thus the returned string is
 always successfully coerced to a bytestring when required unless I'm
 missing something.

 It wouldn't hurt to simply prefix the default format with a `b` but I
 don't think it's worth a backport. Most calls to `__str__` are made
 implicitly through `str()` which automatically tries to `encode('ascii')`
 when fed `unicode` which will never fail given the nature of
 `self.__class__.__name__` on Python 2.

--
Ticket URL: <https://code.djangoproject.com/ticket/25730#comment:3>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.7b8935cec14ccf510a746e43cab5c8f8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to