summaryrefslogtreecommitdiff
path: root/django/utils/encoding.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-10-13 18:06:58 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-10-13 18:25:21 +0200
commitf0c7649b1692f8441eb9b9b923b2bed8e95f9185 (patch)
tree8ee531e9ad078dd525f2364ca1b3d55233eb217b /django/utils/encoding.py
parentddff6522fa72aacc7475ba5cd4bf8683ff12b8c7 (diff)
Fixed #21198 -- Prevented invalid use of @python_2_unicode_compatible.
Thanks jpic for the report and chmodas for working on a patch. Reverts 2ea80b94. Refs #19362. Conflicts: tests/utils_tests/test_encoding.py
Diffstat (limited to 'django/utils/encoding.py')
-rw-r--r--django/utils/encoding.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index ad06336c4d..599952bdeb 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -52,6 +52,10 @@ def python_2_unicode_compatible(klass):
returning text and apply this decorator to the class.
"""
if six.PY2:
+ if '__str__' not in klass.__dict__:
+ raise ValueError("@python_2_unicode_compatible cannot be applied "
+ "to %s because it doesn't define __str__()." %
+ klass.__name__)
klass.__unicode__ = klass.__str__
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
return klass