jazzband / django-formtools

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

Conditionally views and wizard.steps.current maximum recursion depth exceeded #95

Open edgaru opened 7 years ago

edgaru commented 7 years ago

When I use wizard.steps.current into a conditionally function I get maximum recursion depth exceeded.

Code Example:

def conditionally_view(wizard):
     if (wizard.steps.current == 'insurance_coverage') and ('emision_retries' in wizard.request.session) and \
            ('emision_has_error' in wizard.request.session):
          ....

Traceback:

Traceback (most recent call last):
  File "C:\Users\edgar\env\ana_web\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
    response = get_response(request)
  File "C:\Users\edgar\env\ana_web\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\edgar\env\ana_web\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\edgar\env\ana_web\lib\site-packages\django\views\generic\base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 244, in dispatch
    response = super(WizardView, self).dispatch(request, *args, **kwargs)
  File "C:\Users\edgar\env\ana_web\lib\site-packages\django\views\generic\base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Users\edgar\PycharmProjects\ana_web\ana_web\web\views.py", line 68, in get
    step = self.steps.first
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 67, in first
    return self.all[0]
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 49, in all
    return list(self._wizard.get_form_list())
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 222, in get_form_list
    condition = condition(self)
  File "C:\Users\edgar\PycharmProjects\ana_web\ana_web\web\views.py", line 670, in get_poliza_success_call
    if (wizard.steps.current == 'insurance_coverage') and ('emision_retries' in wizard.request.session) and \
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 62, in current
    return self._wizard.storage.current_step or self.first
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 67, in first
    return self.all[0]
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 49, in all
    return list(self._wizard.get_form_list())
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 222, in get_form_list
    condition = condition(self)
  File "C:\Users\edgar\PycharmProjects\ana_web\ana_web\web\views.py", line 670, in get_poliza_success_call
    if (wizard.steps.current == 'insurance_coverage') and ('emision_retries' in wizard.request.session) and \
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 62, in current
    return self._wizard.storage.current_step or self.first
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 67, in first
    return self.all[0]
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 49, in all
    return list(self._wizard.get_form_list())
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 222, in get_form_list
    condition = condition(self)
  File "C:\Users\edgar\PycharmProjects\ana_web\ana_web\web\views.py", line 670, in get_poliza_success_call
    if (wizard.steps.current == 'insurance_coverage') and ('emision_retries' in wizard.request.session) and \
  File "C:\Users\edgar\env\ana_web\lib\site-packages\formtools\wizard\views.py", line 62, in current
....
....
RecursionError: maximum recursion depth exceeded
edgaru commented 7 years ago

I solved it using wizard.storage.current_step instead wizard.steps.current.

mpasternak commented 1 year ago

This problem was reintroduced for me in 2.4 and using wizard.storage.current_step does not fix it.

rob-mccutcheon commented 1 year ago

The example at https://django-formtools.readthedocs.io/en/latest/wizard.html#conditionally-view-skip-specific-steps

does not work with version 2.4 due to this

Is there a version where this is not an issue?

pdelsante commented 1 year ago

Is there a version where this is not an issue?

Version 2.3 does not seem to be affected; instead, I confirm that updating to 2.4 breaks the example.