Backwards incompatible change by #4412 / r7977: get_FIELD_display() returns blank value
|Reported by:||miracle2k||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Previously, get_FIELD_display(), for a blank or unknown value of FIELD, return the value unchanged, e.g. say None or an empty string.
After the change, it returns the automatically inserted blank choice (-------). This is due to it now using field.flatchoices, which is dynamically generated through the get_choices() method, whereas it previously just used field.choices, which contains the unmodified tuple the field receives through init.
This may also be an unwanted discrepancy between the two attributes.
class Whiz(models.Model): CHOICES = ( (1,'First'), (0,'Other'), ) c = models.IntegerField(choices=CHOICES, null=True) >>> w = Whiz(c='') >>> w.save() >>> w.get_c_display() u'' Expected: u'' Got: u'---------'
Change History (7)
Changed 7 years ago by miracle2k
comment:1 Changed 7 years ago by miracle2k
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:4 Changed 7 years ago by evenrik
- Resolution fixed deleted
- Status changed from closed to reopened