Opened 6 years ago
Last modified 6 years ago
#30076 closed Bug
get_FOO_display missing if field choices is specified but falsey — at Initial Version
Reported by: | Joshua Cannon | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.1 |
Severity: | Normal | Keywords: | choices get_FOO_display |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Since Field
checks if choices
is truthy code instead of checking against None
, some model instances aren't receiving the get_FOO_display
method.
Usually the culprit is Field
subclasses doing some kind of dynamic choice generation, providing choices=()
as a sort of fallback. Since ()
is an empty tuple that is falsey, the method never gets added.
So far I've seen 2 libraries that have this "issue", which is likely a small set.
- django-model-utils just gives some dummy choices.
- django-typed-models doesn't have a fix yet.
Note:
See TracTickets
for help on using tickets.