furthemore / APIS

Event Management System for Fan Conventions
http://www.furthemore.org/
GNU General Public License v3.0
11 stars 9 forks source link

Crash on checkout when using Discount code #321

Open anadon opened 5 months ago

anadon commented 5 months ago

Multiple discount codes of the same name are able to be entered when configuring, which may be useful for having codes change value over time or to have codes have number of uses over time. However, this currently causes all codes with that same "CodeName" to be returned which causes a error when registering, resulting in the following stacktrace. registration.models.Discount.MultipleObjectsReturned get() returned more than one Discount -- it returned 2! __ Werkzeug Debugger.pdf

anadon commented 5 months ago
Traceback (most recent call last):
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
    return self.application(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
    response = self.get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/core/handlers/base.py", line 130, in get_response
    response = self._middleware_chain(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/core/handlers/exception.py", line 49, in inner
    response = response_for_exception(request, exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/core/handlers/exception.py", line 114, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/core/handlers/exception.py", line 149, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django_extensions/management/technical_response.py", line 40, in null_technical_500_response
    raise exc_value.with_traceback(tb)
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/Documents/code/APIS/registration/views/cart.py", line 57, in get_cart
    total, total_discount = ordering.get_total(cartItems, [], discount)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/Documents/code/APIS/registration/views/ordering.py", line 178, in get_total
    discount = get_discount_total(disc, item_total)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/Documents/code/APIS/registration/views/ordering.py", line 151, in get_discount_total
    discount = Discount.objects.get(codeName=disc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anadon/.cache/pypoetry/virtualenvs/apis-cpMGNct6-py3.12/lib/python3.12/site-packages/django/db/models/query.py", line 439, in get
    raise self.model.MultipleObjectsReturned(
registration.models.Discount.MultipleObjectsReturned: get() returned more than one Discount -- it returned 2!