#4435 closed (fixed)
[unicode] get_FIELD_display() does not work for None values
Reported by: | Owned by: | Malcolm Tredinnick | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | other branch |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you have a model field with choices and null=True, the model function get_FIELD_display() returns u'None'
if the attribute is None. It should return None
django.db.models.base, lines ~ 322 ff:
def _get_FIELD_display(self, field): value = getattr(self, field.attname) return force_unicode(dict(field.choices).get(value, value))
Either this function, or force_unicode, needs a special check for None.
Change History (5)
comment:1 by , 17 years ago
Version: | SVN → other branch |
---|
comment:2 by , 17 years ago
Owner: | changed from | to
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 17 years ago
Change of mind to the previous comment. I cannot see anywhere at all that we are relying on mapping None -> 'None' via force_unicode. So special-casing None seems reasonable.
comment:4 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
We can't make force_unicode() do this by default, because it has to behave like str() in a bunch of places. I'll add a parameter to ignore such non-strings, though, just like smart_str() currently has. Then we can nail them one-by-one (there shouldn't be too many).