Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Type: KeyError at ... #247

Open
adi- opened this issue Sep 27, 2023 · 4 comments
Open

Exception Type: KeyError at ... #247

adi- opened this issue Sep 27, 2023 · 4 comments

Comments

@adi-
Copy link

adi- commented Sep 27, 2023

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
Copy link

nordost8 commented Feb 1, 2024

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

@ProfRoxas
Copy link

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-
Copy link
Author

adi- commented Jun 13, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants