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

Possible bug when refreshing form? #166

Open
caffiendFrog opened this issue Jan 7, 2020 · 0 comments
Open

Possible bug when refreshing form? #166

caffiendFrog opened this issue Jan 7, 2020 · 0 comments

Comments

@caffiendFrog
Copy link

caffiendFrog commented Jan 7, 2020

Scenario

I am using SessionWizardView which has 3 forms. The forms are all using the same template, which has 3 fields, one of which is a required UUID for a part. The end result is to have 3 unique parts (i.e. UUID must be ... unique). I have validation in my form clean method that checks this. The validation works as expected if the user never refreshes:

  1. User enters UUID "abc" in step 0 and submits
  2. User enters UUID "xyz" in step 1 and submits
  3. User enters UUID "abc" in step 2 and submits
  4. form.is_valid() fails
  5. User sees a validation message about non unique UUID
  6. User is still on step 2

Reproduce

  1. User enters UUID "abc" in step 0 and submits
  2. User is on step 1 and refreshes the page

Expected behavior

  1. User is still on step 1

Actual behavior

  1. Page refresh sends a POST request with data from step 0
  2. formwizard thinks user is on step 0 and has entered "abc"
  3. form.is_valid() fails
  4. User sees a validation message about non unique UUID
  5. User is returned to step 0

This poses a problem for the user because now they are stuck. They have to enter 3 parts and there is no way to remove the barcode "abc" from the formwizard data. Now that the user is back on step 0, there will be no way for them to enter 3 distinct UUID, it will always think one of them is duplicated after step 1.

Diagnosis

I've traced the problem to this bit of code in the post method for WizardView:

form_current_step = management_form.cleaned_data['current_step']
if (form_current_step != self.steps.current and self.storage.current_step is not None):
      # form refreshed, change current step
      self.storage.current_step = form_current_step

In the following, the conditional storage.current_step is not None is always True

Step Action Unique UUID? storage.current_step form_current_step storage.current_step changed
0 submit yes 0 0 No (0)
1 refresh n/a 1 0 Yes (1 -> 0)
1 submit no 1 1 No (1)

It seems to me that we shouldn't be changing the current step when the page is refreshed. I'm not sure if this is expected/designed behavior or if this is a bug.

Thank you in advance for your time.

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

1 participant