Opened 3 years ago

Closed 3 years ago

#17677 closed Bug (fixed)

WizardView.get_form destroys 'instance' and 'queryset' from get_form_kwargs

Reported by: goodtune Owned by: nobody
Component: contrib.formtools Version: 1.4-alpha-1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description

In the case where the wizard author might like to populate the form with an existing model instance or formset from a queryset based through get_form_kwargs it get's destroyed by a call to kwargs.update({'instance': self.get_form_instance(step)}) or kwargs.update({'queryset': self.get_form_instance(step)}).

While I can appreciate that there is already a way to populate this value by overloading the get_form_instance method, I don't think that we should be destructive of another way to achieve it. Additionally I find it less confusing if I can define all kwargs to be passed to my form/formset init method in one place (ie. in get_form_kwargs) rather than splitting this logic into two places.

I've attached a patch against r17511 which includes a test case.

Attachments (2)

17677.diff (5.2 KB) - added by goodtune 3 years ago.
17677-2.diff (5.2 KB) - added by steph 3 years ago.
Updated patch (some test changes)

Download all attachments as: .zip

Change History (4)

Changed 3 years ago by goodtune

comment:1 Changed 3 years ago by jezdez

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

Changed 3 years ago by steph

Updated patch (some test changes)

comment:2 Changed 3 years ago by jezdez

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

In [17651]:

Fixed #17677 -- Made sure the WizardView doesn't accidentally overwrite the instance or queryset form parameters when they are already set by the get_form_kwargs method. Thanks to goodtune and Stephan Jäkel.

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