From 71e5ad248e104f68a0d755cd5f76e86631607be5 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Tue, 27 Nov 2012 09:45:37 +0100 Subject: [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. --- django/db/models/base.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'django') diff --git a/django/db/models/base.py b/django/db/models/base.py index a1f9e2f26e..bf9854d289 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -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__ -- cgit v1.3