#31124: Model.get_FOO_display() does not work correctly with inherited choices. -------------------------------------+------------------------------------- Reporter: Yash Jhunjhunwala | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 3.0 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by felixxm):
* status: closed => new * cc: Carlton Gibson, Sergey Fedoseev (added) * version: 2.2 => 3.0 * resolution: needsinfo => * stage: Unreviewed => Accepted Old description: > 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 New description: 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 -- Comment: 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. -- Ticket URL: <https://code.djangoproject.com/ticket/31124#comment:4> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.40613f755b107502fc665389d0a77f59%40djangoproject.com.