Opened 3 years ago

Closed 2 years ago

Last modified 2 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

Description

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:

# views.py
def _show_repair_item_form_condition(wizard):
    print 'foo'
    return True

@login_required
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 2 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 urls.py), not on every request. While it's not an error to do so, it's a bit inefficient.

comment:2 Changed 2 years ago by lrekucki

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

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

  • Resolution changed from invalid to fixed
Note: See TracTickets for help on using tickets.
Back to Top