Error message when Model.__unicode__() returns None
|Reported by:||lsaffre||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I had already several times the situation that the unicode method of one of my models returned None in some case.
This leads to a "TypeError: coercing to Unicode: need string or buffer, NoneType found" traceback.
That's okay, but sometimes it is not easy to guess *which* model is wrong.
So I took django/db/models/base.py and added the lines marked '+' below:
def __repr__(self): try: u = unicode(self) except (UnicodeEncodeError, UnicodeDecodeError): u = '[Bad Unicode data]' + except TypeError,e: + raise TypeError("%s: %s" % (self.__class__, e)) return smart_str(u'<%s: %s>' % (self.__class__.__name__, u))
Change History (9)
comment:1 Changed 6 years ago by lsaffre
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Summary changed from Error message when __unicode__() returns None to Error message when Model.__unicode__() returns None
comment:2 Changed 5 years ago by russellm
- Has patch set
- Needs tests set
- Triage Stage changed from Unreviewed to Accepted
Changed 4 years ago by mk
comment:6 Changed 4 years ago by jezdez
- Easy pickings unset
- Triage Stage changed from Accepted to Ready for checkin