Opened 5 years ago
Last modified 5 years ago
#31124 closed Bug
Model.get_FOO_display() does not work correctly with inherited choices. — at Version 4
Reported by: | Yash Jhunjhunwala | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.0 |
Severity: | Release blocker | Keywords: | |
Cc: | Carlton Gibson, Sergey Fedoseev | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Given a base model with choices A containing 3 tuples
Child Model inherits the base model overrides the choices A and adds 2 more tuples
get_foo_display does not work correctly for the new tuples added
Example:
class A(models.Model): foo_choice = [("A","output1"),("B","output2")] field_foo = models.CharField(max_length=254,choices=foo_choice) class Meta: abstract = True class B(A): foo_choice = [("A","output1"),("B","output2"),("C","output3")] field_foo = models.CharField(max_length=254,choices=foo_choice)
Upon invoking get_field_foo_display() on instance of B ,
For value "A" and "B" the output works correctly i.e. returns "output1" / "output2"
but for value "C" the method returns "C" and not "output3" which is the expected behaviour
Change History (4)
follow-up: 2 comment:1 by , 5 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Easy pickings: | unset |
Resolution: | → needsinfo |
Status: | new → closed |
Summary: | get foo display - model inheritance does not work correctly → Model.get_FOO_display() does not work correctly with inherited choices. |
follow-up: 3 comment:2 by , 5 years ago
Description: | modified (diff) |
---|
comment:3 by , 5 years ago
comment:4 by , 5 years ago
Cc: | added |
---|---|
Description: | modified (diff) |
Resolution: | needsinfo |
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
Version: | 2.2 → 3.0 |
Thanks for an extra info. I was able to reproduce this issue, e.g.
>>> B.objects.create(field_foo='A').get_field_foo_display() output1 >>> B.objects.create(field_foo='B').get_field_foo_display() output2 >>> B.objects.create(field_foo='C').get_field_foo_display() C
Regression in 2d38eb0ab9f78d68c083a5b78b1eca39027b279a (Django 2.2.7).
Thanks for this report. Can you provide models and describe expected behavior? Can you also check if it's not a duplicate of #30931?, that was fixed in Django 2.2.7.