Skip to content

Commit

Permalink
refactor: Add atomicity to function calls in execute
Browse files Browse the repository at this point in the history
  • Loading branch information
moeez96 committed Apr 10, 2023
1 parent b9f921b commit 54ea975
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ecommerce/extensions/iap/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,16 @@ def post(self, request):
return JsonResponse({'error': ERROR_DURING_PAYMENT_HANDLING}, status=400)

try:
order = self.create_order(request, basket)
with transaction.atomic():
order = self.create_order(request, basket)
except Exception: # pylint: disable=broad-except
# Any errors here will be logged in the create_order method. If we wanted any
# IAP specific logging for this error, we would do that here.
return JsonResponse({'error': ERROR_DURING_ORDER_CREATION}, status=400)

try:
self.handle_post_order(order)
with transaction.atomic():
self.handle_post_order(order)
except Exception: # pylint: disable=broad-except
self.log_order_placement_exception(basket.order_number, basket.id)
return JsonResponse({'error': ERROR_DURING_POST_ORDER_OP}, status=200)
Expand Down

0 comments on commit 54ea975

Please sign in to comment.