Skip to content

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

change webhooks to be called on commit within atomic transactions (#9532)

Jakub1a4aed545eab
diff --git a/saleor/graphql/page/mutations/pages.py b/saleor/graphql/page/mutations/pages.py
index 80eda6a4bd..5ecb277fcb 100644
--- a/saleor/graphql/page/mutations/pages.py
+++ b/saleor/graphql/page/mutations/pages.py
@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Dict, List
import graphene
from django.core.exceptions import ValidationError
+from django.db import transaction
from ....attribute import AttributeInputType, AttributeType
from ....attribute import models as attribute_models
@@ -160,7 +161,7 @@ class PageDelete(ModelDeleteMutation):
page = cls.get_instance(info, **data)
cls.delete_assigned_attribute_values(page)
response = super().perform_mutation(_root, info, **data)
- info.context.plugins.page_deleted(page)
+ transaction.on_commit(lambda: info.context.plugins.page_deleted(page))
return response
@staticmethod
diff --git a/saleor/graphql/product/mutations/channels.py b/saleor/graphql/product/mutations/channels.py
index ddc1e2e231..35b486ddbf 100644
--- a/saleor/graphql/product/mutations/channels.py
+++ b/saleor/graphql/product/mutations/channels.py
@@ -272,7 +272,7 @@ class ProductChannelListingUpdate(BaseChannelListingMutation):
def save(cls, info, product: "ProductModel", cleaned_input: Dict):
cls.update_channels(product, cleaned_input.get("update_channels", []))
cls.remove_channels(product, cleaned_input.get("remove_channels", []))
- info.context.plugins.product_updated(product)
+ transaction.on_commit(lambda: info.context.plugins.product_updated(product))
@classmethod
def perform_mutation(cls, _root, info, id, input):
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 77bdf686a7..8af9db6ea3 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -775,7 +775,9 @@ class ProductDelete(ModelDeleteMutation):
order_pks = draft_order_lines_data.order_pks
if order_pks:
recalculate_orders_task.delay(list(order_pks))
- info.context.plugins.product_deleted(instance, variants_id)
+ transaction.on_commit(
+ lambda: info.context.plugins.product_deleted(instance, variants_id)
+ )
return response