jazzband / django-formtools

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

Exception Type: KeyError at ... #247

Open adi- opened 10 months ago

adi- commented 10 months ago

I get random KeyErrors from time to time. Any clues what its may be?

lib/python3.8/site-packages/formtools/wizard/views.py", line 415, in get_form
   form_class = self.get_form_list()[step]
nordost8 commented 6 months ago

i have the same problem. Everything was fine on Django 4.2.3

ProfRoxas commented 1 month ago

We recently had similar issue and it was even using the wrong form for some step. Turned out it was probably caused by the conditional dict had a function that was checking against the wizard.steps. Worked fine for us after only depending on the cleaned_data in the condition

adi- commented 1 month ago

Traceback:

Traceback (most recent call last):
 File "/opt/venvs/[...]/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
   response = get_response(request)
 File "/opt/venvs/[...]/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
   response = wrapped_callback(request, *callback_args, **callback_kwargs)
 File "/opt/venvs/[...]/lib/python3.8/site-packages/django/views/generic/base.py", line 104, in view
   return self.dispatch(request, *args, **kwargs)
 File "/opt/venvs/[...]/lib/python3.8/site-packages/formtools/wizard/views.py", line 250, in dispatch
   response = super().dispatch(request, *args, **kwargs)
 File "/opt/venvs/[...]/lib/python3.8/site-packages/django/views/generic/base.py", line 143, in dispatch
   return handler(request, *args, **kwargs)
 File "/opt/venvs/[...]/lib/python3.8/site-packages/formtools/wizard/views.py", line 297, in post
   form = self.get_form(data=self.request.POST, files=self.request.FILES)
 File "/opt/venvs/[...]/lib/python3.8/site-packages/formtools/wizard/views.py", line 415, in get_form
   form_class = self.get_form_list()[step]

Exception Type: KeyError at [...]
Exception Value: 'company'

POST:
service_request_wizard_view-current_step = 'company'

any clues?

ProfRoxas commented 1 month ago

we only noticed the function we used in the condition_dict had the wizard passed to it with different steps under one request, which showed wizard.steps.current had different value even though it was the same step (probably checked the next step too somewhere so it passed to it with next step too, which evaulated as false then true right again)

Another side effect we saw it used the wrong form because of this, like used the form of the skipped step instead of the one for the step

I assume you have a condition_dict (because that's usually how the get_form_list() can have missing step) If it refers to the wizard step, can you print the current step under it and see if it changes? If so, try to only depend on the cleaned_data as that will be consistent during the request.

I tried to wrap my head around the code, but i couldn't get much of it, so if it's not there, i dont have an idea right now