diff --git a/django/db/models/base.py b/django/db/models/base.py
index 4aa6cfa..ab23be8 100644
a
|
b
|
class Model(object):
|
371 | 371 | u = unicode(self) |
372 | 372 | except (UnicodeEncodeError, UnicodeDecodeError): |
373 | 373 | u = '[Bad Unicode data]' |
| 374 | except TypeError, e: |
| 375 | raise TypeError("%s: %s" % (self.__class__, e)) |
374 | 376 | return smart_str(u'<%s: %s>' % (self.__class__.__name__, u)) |
375 | 377 | |
376 | 378 | def __str__(self): |
diff --git a/tests/regressiontests/model_regress/models.py b/tests/regressiontests/model_regress/models.py
index f30b3ee..e1c03fd 100644
a
|
b
|
class BrokenUnicodeMethod(models.Model):
|
57 | 57 | |
58 | 58 | class NonAutoPK(models.Model): |
59 | 59 | name = models.CharField(max_length=10, primary_key=True) |
| 60 | |
| 61 | class NoneUnicodeMethod(models.Model): |
| 62 | def __unicode__(self): |
| 63 | # Intentionally broken. Returns None |
| 64 | return None |
diff --git a/tests/regressiontests/model_regress/tests.py b/tests/regressiontests/model_regress/tests.py
index a103590..877aa92 100644
a
|
b
|
from django.test import TestCase, skipUnlessDBFeature
|
6 | 6 | from django.utils import tzinfo |
7 | 7 | |
8 | 8 | from models import (Worker, Article, Party, Event, Department, |
9 | | BrokenUnicodeMethod, NonAutoPK) |
| 9 | BrokenUnicodeMethod, NonAutoPK, NoneUnicodeMethod) |
10 | 10 | |
11 | 11 | |
12 | 12 | |
… |
… |
class ModelTests(TestCase):
|
145 | 145 | b = BrokenUnicodeMethod.objects.create(name="Jerry") |
146 | 146 | self.assertEqual(repr(b), "<BrokenUnicodeMethod: [Bad Unicode data]>") |
147 | 147 | |
| 148 | n = NoneUnicodeMethod() |
| 149 | self.assertRaises(TypeError, lambda: unicode(n)) |
| 150 | self.assertRaisesRegexp( |
| 151 | TypeError, |
| 152 | "<class 'regressiontests.model_regress.models.NoneUnicodeMethod'>: coercing to Unicode: need string or buffer, NoneType found", |
| 153 | lambda: repr(NoneUnicodeMethod()) |
| 154 | ) |
| 155 | |
148 | 156 | @skipUnlessDBFeature("supports_timezones") |
149 | 157 | def test_timezones(self): |
150 | 158 | # Saving an updating with timezone-aware datetime Python objects. |