Skip to content

Commit

Permalink
Add transaction that rollsback on error
Browse files Browse the repository at this point in the history
  • Loading branch information
viggo-devries committed Sep 17, 2024
1 parent 164b7f4 commit 92062f1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions oscarapi/utils/categories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.utils.translation import gettext as _
from django.db import transaction

from rest_framework.exceptions import NotFound

Expand Down Expand Up @@ -74,12 +75,13 @@ def find_from_full_slug(breadcrumb_str, separator="/"):


def upsert_categories(data):
categories_to_update, fields_to_update = _upsert_categories(data)
with transaction.atomic():
categories_to_update, fields_to_update = _upsert_categories(data)

if categories_to_update and fields_to_update:
Category.objects.bulk_update(categories_to_update, fields_to_update)
if categories_to_update and fields_to_update:
Category.objects.bulk_update(categories_to_update, fields_to_update)

Category.fix_tree()
Category.fix_tree()


def _upsert_categories(data, parent_category=None):
Expand Down

0 comments on commit 92062f1

Please sign in to comment.