jazzband / django-formtools

A set of high-level abstractions for Django forms
https://django-formtools.readthedocs.io
BSD 3-Clause "New" or "Revised" License
797 stars 135 forks source link

multiple `get_form_initial` calls when `condition_dict` is used #134

Open adi- opened 5 years ago

adi- commented 5 years ago

Don't know why, but when I use condition_dict, the get_form_initial def is called multiple times.

The above problem is seen when I use wizard.get_cleaned_data_for_step() in condition def.

Any clues?

bvishal8510 commented 5 years ago

@adi- Can you please tell about the file and line number where you find this error

adi- commented 5 years ago

I am implementing as exampled here: https://django-formtools.readthedocs.io/en/latest/wizard.html#formtools.wizard.views.WizardView.condition_dict

When wizard.get_cleaned_data_for_step('0') is present (not #) in views.py, get_form_initial is initiated multiple times. When you rem this line, everything works as expected.

adi- commented 5 years ago

I have also added hooks (simple print statement) for get_form_kwargs, get_form_initial and condition function. I don't see any reason, why those functions are fired multiple times... But only when wizard.get_cleaned_data_for_step is present in condition function.

GiuseppePegasus commented 2 years ago

I have the same problem..any solution?

claudep commented 2 years ago

Any patch with tests will be welcome!

Starou commented 2 years ago

@GiuseppePegasus : as a workaround I use wizard.storage.data['step_data'] to avoid infinite recursion or to fire wizard's methods too early (get_form(), get_form_initial()).

shanx commented 1 year ago

I think the problem is: https://github.com/jazzband/django-formtools/blob/master/formtools/wizard/views.py#L47

This all property is used a lot and recalculates the form_list using the conditions each time it is invoked. I actually had this problem too locally and found out that Django's debug toolbars way of displaying info nicely caused an excessive amount of all invocations. Removing the debug toolbar already significantly improved the behaviour.

It might be nice to generate the form_list once per use of the wizard.