Opened 11 years ago
Closed 11 years ago
#20812 closed Bug (fixed)
django.utils.encoding.force_text() should call unicode() instead of __unicode__()
Reported by: | Owned by: | Florian Apolloner | |
---|---|---|---|
Component: | Utilities | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Unlike the unicode()
builtin function, the method __unicode__()
does not validate its return type.
If people wrote a buggy __unicode__
which does not return str
or unicode
, this can lead to a situation where force_text()
will return non-text, and so the bug may only appear much, much later when other parts of the application assumes they were getting text and often it will become very difficult to find how the non-string object came from.
Expected result:
force_text()
should be switched to use unicode()
so returning non-text from __unicode__()
will immediately raise an error at the point where the error would have been obvious.
Change History (4)
comment:2 by , 11 years ago
Description: | modified (diff) |
---|
comment:3 by , 11 years ago
comment:4 by , 11 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
Version: | 1.5 → master |
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I think the current implementation may have something to do with the cross python 2/3 compatibility. We could get the same effect by calling
six.text_type(obj.__unicode__())
, but I'm not sure if that's the best approach.