Opened 7 years ago
Closed 7 years ago
#30076 closed Bug (fixed)
get_FOO_display missing if field choices is specified but falsey
| Reported by: | Joshua Cannon | Owned by: | Joshua Cannon |
|---|---|---|---|
| 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 (last modified by )
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 falsy, 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.
Change History (5)
comment:1 by , 7 years ago
| Owner: | changed from to |
|---|
comment:2 by , 7 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 7 years ago
| Has patch: | set |
|---|
comment:4 by , 7 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.
PR