Opened 11 years ago

Closed 11 years ago

#21259 closed Bug (fixed)

Wizard sets queryset instead of instance on InlineFormset

Reported by: banderkat@… Owned by: nobody
Component: contrib.formtools Version: dev
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

Description

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:
https://github.com/flibbertigibbet/django/commit/885798aa250544bd5c6d3a7325dc5c20c0795f2c

Change History (7)

comment:1 by Tim Graham, 11 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

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

comment:2 by kkillebrew, 11 years ago

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

https://github.com/django/django/pull/1726

comment:3 by Tim Graham, 11 years ago

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 by kkillebrew, 11 years ago

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

comment:5 by Tim Graham, 11 years ago

I believe you will need to include:

class Meta:
    app_label = 'formtools'

on the model.

comment:6 by kkillebrew, 11 years ago

Patch needs improvement: unset

That worked! Thanks.

comment:7 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 7e5d7a76bf60564d39d25a101380e47da7f1e2f6:

Fixed #21259 -- Fixed formstools wizard for InlineFormSet.

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