Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use select_for_update only in a transaction

Artur Smętaedaf93bae61
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.py
index 5971fc6b82..cc0f92d212 100644
--- a/saleor/checkout/core.py
+++ b/saleor/checkout/core.py
@@ -236,7 +236,8 @@ class Checkout(object):
else:
order_data['user_email'] = self.email
- voucher = self._get_voucher()
+ voucher = self._get_voucher(
+ vouchers=Voucher.objects.active().select_for_update())
if voucher is not None:
discount = self.discount
order_data['voucher'] = voucher
@@ -264,10 +265,11 @@ class Checkout(object):
return order
- def _get_voucher(self):
+ def _get_voucher(self, vouchers=None):
voucher_code = self.voucher_code
if voucher_code is not None:
- vouchers = Voucher.objects.active().select_for_update()
+ if vouchers is None:
+ vouchers = Voucher.objects.active()
try:
return vouchers.get(code=self.voucher_code)
except Voucher.DoesNotExist: