Opened 2 years ago

Closed 2 years ago

#21259 closed Bug (fixed)

Wizard sets queryset instead of instance on InlineFormset

Reported by: banderkat@… Owned by: nobody
Component: contrib.formtools Version: master
Severity: Normal Keywords: wizard, InlineFormSet
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Because InlineFormSet subclasses BaseModelFormSet, the wizard thinks it's like any BaseModelFormSet and incorrectly initializes the form by setting the form's queryset instead of the form's instance. An InlineFormSet needs to have its instance set to the parent model object instead.

Currently, attempting to set self.instance for the InlineFormSet in the wizard's get_form_instance results in an AttributeError saying "object has no attribute 'none'" as the wizard attempts to set the form's queryset (instead of instance) with it's self.instance.

I have a fix to propose here:

Change History (7)

comment:1 Changed 2 years ago by timo

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Tentatively accepting, however, a test case demonstrating the problem and proving the fix works is necessary for this to be committed.

comment:2 Changed 2 years ago by kkillebrew

Okay, I've added a test to the pull request.

comment:3 Changed 2 years ago by timo

  • Needs tests unset
  • Patch needs improvement set

Thanks, I left comments for improve on the PR. Please uncheck "Patch needs improvement" when you update it.

comment:4 Changed 2 years ago by kkillebrew

Thanks for the notes. I'm having some issues with the test models. I put the new in django.contrib.formtools.tests, and I see says in the verbose output 'Creating table formtools_testmodel', but then the test fails with 'OperationalError: no such table: tests_poet'.

comment:5 Changed 2 years ago by timo

I believe you will need to include:

class Meta:
    app_label = 'formtools'

on the model.

comment:6 Changed 2 years ago by kkillebrew

  • Patch needs improvement unset

That worked! Thanks.

comment:7 Changed 2 years ago by Tim Graham <timograham@…>

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

In 7e5d7a76bf60564d39d25a101380e47da7f1e2f6:

Fixed #21259 -- Fixed formstools wizard for InlineFormSet.

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