OrderChangeManager: Prevent race conditions (Z#23131769) (#3623)

This commit is contained in:
Raphael Michel
2023-10-09 16:00:58 +02:00
committed by GitHub
parent 0cbb38f3d4
commit d8ecb43e5d
2 changed files with 7 additions and 0 deletions

View File

@@ -139,6 +139,8 @@ error_messages = {
'meantime. Please see below for details.'
),
'internal': gettext_lazy("An internal error occurred, please try again."),
'race_condition': gettext_lazy("This order was changed by someone else simultaneously. Please check if your "
"changes are still accurate and try again."),
'empty': gettext_lazy("Your cart is empty."),
'max_items_per_product': ngettext_lazy(
"You cannot select more than %(max)s item of the product %(product)s. We removed the surplus items from your cart.",
@@ -2714,6 +2716,10 @@ class OrderChangeManager:
self._payment_fee_diff()
with transaction.atomic():
locked_instance = Order.objects.select_for_update(of=OF_SELF).get(pk=self.order.pk)
if locked_instance.last_modified != self.order.last_modified:
raise OrderError(error_messages['race_condition'])
if self.order.status in (Order.STATUS_PENDING, Order.STATUS_PAID):
if check_quotas:
self._check_quotas()

View File

@@ -3733,6 +3733,7 @@ def test_issue_when_paid_and_changed(event):
op.refresh_from_db()
assert op.secret == gc1.secret
order.refresh_from_db()
ocm = OrderChangeManager(order)
ocm.add_position(ticket, None, Decimal('12.00'))
ocm.commit()