ModelReprMixin: Fix handling of missing __unicode__ function.

The old behavior was to raise an exception, but Django was catching
the exception and doing unexpected things. For instance, in the
manage.py shell, printing out a ModelReprMixin object (with
__unicode__ not implemented) would result in nothing being printed,
rather than it raising a error or otherwise alerting the programmer as
to what was going on.
This commit is contained in:
Rishi Gupta
2016-08-01 15:57:06 -07:00
committed by Tim Abbott
parent 9151ee42e9
commit 948ea7663c

View File

@@ -83,7 +83,9 @@ class ModelReprMixin(object):
"""
def __unicode__(self):
# type: () -> text_type
raise NotImplementedError("__unicode__ is not implemented in subclass of ModelReprMixin")
# Originally raised an exception, but Django (e.g. the ./manage.py shell)
# was catching the exception and not displaying any sort of error
return u"Implement __unicode__ in your subclass of ModelReprMixin!"
def __str__(self):
# type: () -> str