Opened 7 years ago

Closed 7 years ago

Last modified 4 years ago

#10799 closed (fixed)

List editable breaks with model inheritance and parent_link=True

Reported by: willhardy Owned by: Alex
Component: contrib.admin Version: master
Severity: Keywords: list_editable parent_link inheritance
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Similar symptoms to #10622, the admin site raises an exception where the model explicity defines a parent_link and list_editable is set in the model's admin.

I have attached a regression test that shows this in action.

Attachments (2)

list_editable_and_parent_link.diff (2.3 KB) - added by willhardy 7 years ago.
Regression test showing this bug in action
list-editable.diff (6.5 KB) - added by Alex 7 years ago.

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by willhardy

Regression test showing this bug in action

comment:1 Changed 7 years ago by willhardy

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

A couple of extra bits of potentially useful information:

  1. exception appears whether or not parent_link is set as a primary_key.
  1. looking at line 950 of django/contrib/admin/
        elif self.list_editable:
            FormSet = self.get_changelist_formset(request)
            formset = cl.formset = FormSet(queryset=cl.result_list)

The FormSet here looks ok (parent_link and non-parent_link version appear to be the same), but each of the forms in formset.forms is missing the field for the primary key. The result_list is of course the same with or without parent_link.

I find this strange because it appears to use the (no doubt well-tested) generic factory functions from forms.models.

I don't know the internal django code well enough to give a useful opinion here, but this is what I was able to observe.

comment:2 Changed 7 years ago by Alex

  • Owner changed from nobody to Alex
  • Triage Stage changed from Unreviewed to Accepted

Assigning to me.

Changed 7 years ago by Alex

comment:3 Changed 7 years ago by Alex

  • Has patch set

comment:4 Changed 7 years ago by willhardy

I probably should have given my regression test a more descriptive title and a docstring, eg:

    def test_inheritance_parent_link(self):
        " Ensure that the admin list_editable view works for models with parent_link. "

comment:5 Changed 7 years ago by jacob

  • Triage Stage changed from Accepted to Ready for checkin

comment:6 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(In [10590]) Fixed #10799: fixed the use of list_editable with model inheritance and custom one-to-one parent links. Thanks, Alex Gaynor.

comment:7 Changed 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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