Opened 6 years ago

Closed 6 years ago

#26537 closed Bug (duplicate)

BaseInlineFormSet Adds N Entries to form._meta.fields For FK

Reported by: David Sanders Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently BaseInlineFormSet appends the FK name for the formset to the fields for the form Meta every time add_fields runs, so with you end up with N fields where N - 1 are duplicates. As each form is instantiated it'll see a different version of the list.

Example based on tests/inline_formsets/tests.py:

>>> poet = Poet.objects.create(name='test')
>>> poet.poem_set.create(name='first test poem')
>>> poet.poem_set.create(name='second test poem')
>>> poet.poem_set.create(name='third test poem')
>>> PoemFormSet = inlineformset_factory(Poet, Poem, fields=('name',), extra=0)
>>> formset = PoemFormSet(None, instance=poet)
>>> PoemFormSet.form._meta.fields
['name', 'poet', 'poet', 'poet']

Change History (3)

comment:1 Changed 6 years ago by David Sanders

Submitted PR #6503.

comment:2 Changed 6 years ago by David Sanders

Type: UncategorizedBug

comment:3 Changed 6 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

Duplicate of #21332

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