Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#18803 closed Bug (fixed)

Django FormWizard.as_view condition_dict callable called multiple times?

Reported by: mikewatsup@… Owned by: nobody
Component: contrib.formtools Version: 1.4
Severity: Release blocker Keywords: form wizard, as_view, condition_dict argument
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The following is a snippet of how I have setup my FormWizard. When I hit this view function, 'bar' gets printed once and 'foo' gets printed 7 times:

def _show_repair_item_form_condition(wizard):
    print 'foo'
    return True

def workshop(request):
    print 'bar'
    cw = WorkshopWizard.as_view([WorkshopRepairItemFormSet, EmptyForm], condition_dict={'0': _show_repair_item_form_condition})
    return cw(request)

I have looked at the implmentation of the as_view function and can't find any trace of a bug causing this to happen. There is no documentation on the web about this issue either.

Any ideas?

Thanks, Mike

Change History (3)

comment:1 Changed 6 years ago by Łukasz Rekucki

This isn't a bug. The wizard doesn't make any guarantees about calling the conditions only once. On the contrary, the whole point of having a callable is being able to dynamically adjust the list of forms based on validation results (so the form_list will differ between validation and rendering).

PS. The as_view() method is intended to be called only once per life of application (usually in, not on every request. While it's not an error to do so, it's a bit inefficient.

comment:2 Changed 6 years ago by Łukasz Rekucki

Resolution: invalid
Status: newclosed

comment:3 Changed 6 years ago by JasonL.Thompson <thompso575@…>

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