Opened 6 years ago

Closed 6 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 Joshua Cannon)

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.

Change History (5)

comment:1 by Joshua Cannon, 6 years ago

Owner: changed from nobody to Joshua Cannon

comment:2 by Simon Charette, 6 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Joshua Cannon, 6 years ago

Has patch: set

comment:4 by Joshua Cannon, 6 years ago

Description: modified (diff)

comment:5 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 16a5a2a2:

Fixed #30076 -- Added Model.get_FOO_display() even if field's choices are empty.

Note: See TracTickets for help on using tickets.
Back to Top