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

Applying voucher code through "amend" view gives a 500 server error #133

Open
rfk opened this issue Jul 23, 2017 · 2 comments · May be fixed by #144
Open

Applying voucher code through "amend" view gives a 500 server error #133

rfk opened this issue Jul 23, 2017 · 2 comments · May be fixed by #144

Comments

@rfk
Copy link

rfk commented Jul 23, 2017

I attempted to apply a voucher code to a user using the staff "amend invoice" view, but got the following traceback:

ERROR 2017-07-17 19:59:08,208 base 19647 139739945805568 Internal Server Error: /tickets/amend/428
Traceback (most recent call last):
  File "/srv/http/2017.pycon-au.org/symposion/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/srv/http/2017.pycon-au.org/symposion/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/srv/http/2017.pycon-au.org/symposion/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/srv/http/2017.pycon-au.org/symposion/src/registrasion/registrasion/views.py", line 968, in amend_registration
    for item, form in zip(items, formset):
  File "/srv/http/2017.pycon-au.org/symposion/lib/python2.7/site-packages/django/forms/formsets.py", line 81, in __len__
    return len(self.forms)
  File "/srv/http/2017.pycon-au.org/symposion/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/srv/http/2017.pycon-au.org/symposion/lib/python2.7/site-packages/django/forms/formsets.py", line 144, in forms
    for i in range(self.total_form_count())]
  File "/srv/http/2017.pycon-au.org/symposion/lib/python2.7/site-packages/django/forms/formsets.py", line 116, in total_form_count
    return min(self.management_form.cleaned_data[TOTAL_FORM_COUNT], self.absolute_max)
  File "/srv/http/2017.pycon-au.org/symposion/lib/python2.7/site-packages/django/forms/formsets.py", line 98, in management_form
    code='missing_management_form',
ValidationError: [u'ManagementForm data is missing or has been tampered with']

The problem appears to be that the "apply voucher" form does not include any of the metadata about the products form. The formset constructed here is thus invalid:

https://github.com/chrisjrn/registrasion/blob/master/registrasion/views.py#L961

It cannot be iterated over, producing the above traceback.

I managed to work around this on the pyconau2017 site editing the HTML, putting invalid "product" form data in the "voucher" form so that it will pass the above checks and proceed to apply the voucher.

It may be that adding an if formset.is_valid(): guard around this block of code:

https://github.com/chrisjrn/registrasion/blob/master/registrasion/views.py#L967

Will be enough to fix the issue. I'm sorry I don't have the bandwidth to set up a dev environment and dig in and submit a fix as a PR :-(

@rfk
Copy link
Author

rfk commented Jul 23, 2017

For reference, here's the terrible thing I did to work around this in the pyconau website:

  • In the "amend cart" HTML page there are two forms, one for "product" and one for "voucher".
  • Use the debug console to copy all the hidden form fields from the "product" form into the "voucher" form. These carry the metadata about the form that causes the above traceback if missing.
  • Enter the voucher code and submit the modified form.

IIRC it won't show any confirmation that the voucher code was applied, but if you go to generate and invoice and checkout then it should successfully show the voucher discounts as being applied.

@chrisjrn
Copy link
Owner

chrisjrn commented Jul 23, 2017 via email

@jamezpolley jamezpolley linked a pull request Dec 31, 2017 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants