ValueError: There is already an order with number 100551
matburnham opened this issue · comments
Issue Summary
(Some, ~20%) of my orders are being processed, paid for (via django-oscar-paypal) but then not created as orders. I've found errors repeated errors in the log as below.
Steps to Reproduce
Difficult, I think this is down to database state but I don't know how I've got to that point.
- Put site live.
- Take orders.
- Find that some orders are being duplicated, and others are paid for but not recorded.
- Dig about with customer.
- Find they're experiencing errors then trying again:
- Refund the duplicated orders.
- Recreate the lost order.
Technical details
- Python version: 3.8.10
- Django version: 4.2.9
- Oscar version: 3.2.3
- Django-Oscar-Paypal: 2.0.0 + patch to dump version dependency (24e1477f9b7dd8d020b4b14c48d34e0f4e9b2136)
Error log
[2024-02-08 19:53:43 +0000] [1470626] [DEBUG] GET /checkout/paypal/preview/551/
[2024-02-08 19:53:52 +0000] [1470625] [DEBUG] POST /checkout/paypal/place-order/551/
Order #100551: unhandled exception while placing order (There is already an order with number 100551)
Traceback (most recent call last):
File ".../lib/python3.8/site-packages/oscar/apps/checkout/views.py", line 665, in submit
return self.handle_order_placement(
File ".../lib/python3.8/site-packages/oscar/apps/checkout/mixins.py", line 110, in handle_order_placement
order = self.place_order(
File ".../lib/python3.8/site-packages/oscar/apps/checkout/mixins.py", line 162, in place_order
order = OrderCreator().place_order(
File ".../lib/python3.8/site-packages/oscar/apps/order/utils.py", line 72, in place_order
raise ValueError(
ValueError: There is already an order with number 100551
[2024-02-08 19:55:16 +0000] [1470625] [DEBUG] POST /checkout/paypal/place-order/551/
[2024-02-08 19:55:16 +0000] [1470626] [DEBUG] GET /basket/
[2024-02-08 19:55:22 +0000] [1470625] [DEBUG] GET /checkout/
[2024-02-08 19:55:22 +0000] [1470627] [DEBUG] GET /checkout/shipping-address/
[2024-02-08 19:55:30 +0000] [1470625] [DEBUG] POST /checkout/shipping-address/
[2024-02-08 19:55:30 +0000] [1470627] [DEBUG] GET /checkout/shipping-method/
[2024-02-08 19:55:30 +0000] [1470625] [DEBUG] GET /checkout/payment-method/
[2024-02-08 19:55:30 +0000] [1470627] [DEBUG] GET /checkout/payment-details/
[2024-02-08 19:55:35 +0000] [1470625] [DEBUG] GET /checkout/paypal/payment/
[2024-02-08 19:55:44 +0000] [1470626] [DEBUG] GET /checkout/paypal/preview/551/
[2024-02-08 19:55:50 +0000] [1470625] [DEBUG] POST /checkout/paypal/place-order/551/
Order #100551: unhandled exception while placing order (There is already an order with number 100551)
Traceback (most recent call last):
File ".../lib/python3.8/site-packages/oscar/apps/checkout/views.py", line 665, in submit
return self.handle_order_placement(
File ".../lib/python3.8/site-packages/oscar/apps/checkout/mixins.py", line 110, in handle_order_placement
order = self.place_order(
File ".../lib/python3.8/site-packages/oscar/apps/checkout/mixins.py", line 162, in place_order
order = OrderCreator().place_order(
File ".../lib/python3.8/site-packages/oscar/apps/order/utils.py", line 72, in place_order
raise ValueError(
ValueError: There is already an order with number 100551
Analysis
I run an annual event. Order number 100551 references an order from 2023 from the same user. Order number is derived from the cart number. I seem to have an open cart from a more than a year ago which is attempting to be re-used.
Why? How do I fix this? Presumably I don't want to just delete the carts as order numbers may then clash later. Should I just close all open carts? Is the order process documented anywhere?
Remaining issue
Why do carts get into this state? Could place_order handle this?
Looks like this may have been caused by something similar to #3768