1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

[1.5.x] Fixed #19362 -- Detected invalid use of @python_2_unicode_compatible.

Thanks m3wolf for the report and akaariai for reproducing the problem.

Backport of 2ea80b9.
This commit is contained in:
Aymeric Augustin
2012-11-27 09:45:37 +01:00
parent 7c91b67cfa
commit 71e5ad248e
3 changed files with 24 additions and 1 deletions

View File

@@ -416,6 +416,11 @@ class Model(six.with_metaclass(ModelBase, object)):
def __str__(self):
if not six.PY3 and hasattr(self, '__unicode__'):
if type(self).__unicode__ == Model.__str__:
klass_name = type(self).__name__
raise RuntimeError("%s.__unicode__ is aliased to __str__. Did"
" you apply @python_2_unicode_compatible"
" without defining __str__?" % klass_name)
return force_text(self).encode('utf-8')
return '%s object' % self.__class__.__name__