#30280 closed Bug (fixed)
Model_get_FIELD_display() returns proxies in 2.2rc1 but always returned strings previously
| Reported by: | Matthias Kestenholz | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 2.2 |
| Severity: | Release blocker | 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 (last modified by )
I'm not sure whether that was wanted but cc79c7ee637e65c8da27e56d746c87903d5ec901 (#27795) introduced a change where code which calls get_*_display got a string previously and now gets a proxy under some circumstances.
If this isn't wanted (and I cannot find anything in the release notes saying that it is) then that's a regression which should be fixed before releasing Django 2.2.
Change History (5)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
| Description: | modified (diff) |
|---|---|
| Summary: | _get_FIELD_display returns proxies in 2.2rc1 but always returned strings previously → Model_get_FIELD_display() returns proxies in 2.2rc1 but always returned strings previously |
| Triage Stage: | Unreviewed → Accepted |
Probably str() could be used where force_text() was used previously. By the way, you should explain how to reproduce the issue, i.e. what "under some circumstances" means.
comment:3 by , 7 years ago
You're right, thanks. I could have explained it better.
The code which failed was:
class Project(Model):
ACQUISITION = "acquisition"
TYPE_CHOICES = [
(ACQUISITION, _("Acquisition")),
...
]
type = models.CharField(_("type"), choices=TYPE_CHOICES, max_length=20)
closed_on = models.DateField(_("closed on"), blank=True, null=True)
def pretty_status(self):
parts = [self.get_type_display()]
if self.closed_on:
parts.append(
gettext("closed on %s") % local_date_format(self.closed_on, "d.m.Y")
)
return ", ".join(parts)
... thinking about this some more, maybe it makes sense to return lazy strings when using lazy strings inside
choices.If that's the case this would certainly warrant a mention in the release notes (or maybe I haven't found it?)