diff options
| author | Karen Tracey <kmtracey@gmail.com> | 2008-11-16 18:58:43 +0000 |
|---|---|---|
| committer | Karen Tracey <kmtracey@gmail.com> | 2008-11-16 18:58:43 +0000 |
| commit | 8e350d036ce6e12b2c2e9229c6b00d4da7823ffb (patch) | |
| tree | 5d51dead0070fa62e38c9fa211894338828e3c12 /django/db | |
| parent | bcb4693e1d53c7a216804072649dd801628e4fa8 (diff) | |
Fixed #9608: Ensured a Model's default repr() is printable even if its __unicode__ method raises a Unicode error.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9475 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/base.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index f94d25c9f5..bf6588d7fe 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -266,7 +266,11 @@ class Model(object): signals.post_init.send(sender=self.__class__, instance=self) def __repr__(self): - return smart_str(u'<%s: %s>' % (self.__class__.__name__, unicode(self))) + try: + u = unicode(self) + except (UnicodeEncodeError, UnicodeDecodeError): + u = '[Bad Unicode data]' + return smart_str(u'<%s: %s>' % (self.__class__.__name__, u)) def __str__(self): if hasattr(self, '__unicode__'): |
