Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31124 closed Bug (fixed)

Model.get_FOO_display() does not work correctly with inherited choices. — at Version 2

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 Yash Jhunjhunwala)

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 = Choices(("A","output1"),("B","output2"))
   field_foo = models.CharField(max_length=254,choices=foo_choice)
   class Meta:
       abstract:True

class B(A):
   foo_choice = Choices(("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 (2)

comment:1 by Mariusz Felisiak, 4 years ago

Component: UncategorizedDatabase layer (models, ORM)
Easy pickings: unset
Resolution: needsinfo
Status: newclosed
Summary: get foo display - model inheritance does not work correctlyModel.get_FOO_display() does not work correctly with inherited choices.

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.

in reply to:  1 comment:2 by Yash Jhunjhunwala, 4 years ago

Description: modified (diff)

Replying to felixxm:

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.

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