Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
use call_event class method on all mutations which triggers webhooks (#14370)
Artur9cf6057a1d32
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9749e3d8ce..79da0f8983 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,7 +5,7 @@ All notable, unreleased changes to this project will be documented in this file.# 3.18.0 [Unreleased]### Breaking changes-- Optimize number of queries in bulk mutations when calling Webhooks. This change affects only users of open-source Saleor, who have their own custom plugin implementations. To adjust to this change, the `webhooks` parameter should be added to any of the affected method. Affected methods:+- Optimize number of queries in bulk mutations when calling webhooks. This change affects only users of open-source Saleor, who have their own custom plugin implementations. To adjust to this change, the `webhooks` parameter should be added to any of the affected method. Affected methods:- `attribute_updated`- `attribute_deleted`- `attribute_value_deleted`diff --git a/saleor/graphql/account/bulk_mutations/customer_bulk_delete.py b/saleor/graphql/account/bulk_mutations/customer_bulk_delete.pyindex 940e4b1027..c2a985a002 100644--- a/saleor/graphql/account/bulk_mutations/customer_bulk_delete.py+++ b/saleor/graphql/account/bulk_mutations/customer_bulk_delete.py@@ -53,4 +53,4 @@ class CustomerBulkDelete(CustomerDeleteMixin, UserBulkDelete):webhooks = get_webhooks_for_event(WebhookEventAsyncType.CUSTOMER_DELETED)manager = get_plugin_manager_promise(info.context).get()for instance in instances:- manager.customer_deleted(instance, webhooks=webhooks)+ cls.call_event(manager.customer_deleted, instance, webhooks=webhooks)diff --git a/saleor/graphql/discount/mutations/bulk_mutations.py b/saleor/graphql/discount/mutations/bulk_mutations.pyindex 54b2530f10..c7d97b3702 100644--- a/saleor/graphql/discount/mutations/bulk_mutations.py+++ b/saleor/graphql/discount/mutations/bulk_mutations.py@@ -97,7 +97,9 @@ class SaleBulkDelete(ModelBulkDeleteMutation):webhooks = get_webhooks_for_event(WebhookEventAsyncType.SALE_DELETED)manager = get_plugin_manager_promise(info.context).get()for sale, catalogue_info in sales_and_catalogue_infos:- manager.sale_deleted(sale, catalogue_info, webhooks=webhooks)+ cls.call_event(+ manager.sale_deleted, sale, catalogue_info, webhooks=webhooks+ )update_products_discounted_prices_for_promotion_task.delay(list(product_ids))@@ -154,4 +156,4 @@ class VoucherBulkDelete(ModelBulkDeleteMutation):webhooks = get_webhooks_for_event(WebhookEventAsyncType.VOUCHER_DELETED)manager = get_plugin_manager_promise(info.context).get()for voucher in vouchers:- manager.voucher_deleted(voucher, webhooks=webhooks)+ cls.call_event(manager.voucher_deleted, voucher, webhooks=webhooks)diff --git a/saleor/graphql/discount/mutations/promotion/promotion_bulk_delete.py b/saleor/graphql/discount/mutations/promotion/promotion_bulk_delete.pyindex 989ed50fd2..eb1bb93e37 100644--- a/saleor/graphql/discount/mutations/promotion/promotion_bulk_delete.py+++ b/saleor/graphql/discount/mutations/promotion/promotion_bulk_delete.py@@ -43,7 +43,6 @@ class PromotionBulkDelete(ModelBulkDeleteMutation):product_ids = cls.get_product_ids(queryset)promotions = [promotion for promotion in queryset]queryset.delete()-manager = get_plugin_manager_promise(info.context).get()webhooks = get_webhooks_for_event(WebhookEventAsyncType.PROMOTION_DELETED)for promotion in promotions:diff --git a/saleor/graphql/discount/mutations/sale/sale_create.py b/saleor/graphql/discount/mutations/sale/sale_create.pyindex 6247fa2fc2..2890575b1a 100644--- a/saleor/graphql/discount/mutations/sale/sale_create.py+++ b/saleor/graphql/discount/mutations/sale/sale_create.py@@ -139,8 +139,8 @@ class SaleCreate(ModelMutation):cls.call_event(manager.sale_created, instance, catalogue_info)cls.send_sale_toggle_notification(manager, instance, catalogue_info)- @staticmethod- def send_sale_toggle_notification(manager, instance, catalogue):+ @classmethod+ def send_sale_toggle_notification(cls, manager, instance, catalogue):"""Send a notification about starting or ending sale if it hasn't been sent yet.Send the notification when the start date is before the current date and the@@ -152,6 +152,6 @@ class SaleCreate(ModelMutation):end_date = instance.end_dateif (start_date and start_date <= now) and (not end_date or not end_date <= now):- manager.sale_toggle(instance, catalogue)+ cls.call_event(manager.sale_toggle, instance, catalogue)instance.last_notification_scheduled_at = nowinstance.save(update_fields=["last_notification_scheduled_at"])diff --git a/saleor/graphql/discount/mutations/sale/sale_update.py b/saleor/graphql/discount/mutations/sale/sale_update.pyindex 043728b750..e879cc5631 100644--- a/saleor/graphql/discount/mutations/sale/sale_update.py+++ b/saleor/graphql/discount/mutations/sale/sale_update.py@@ -217,9 +217,9 @@ class SaleUpdate(ModelMutation):manager, instance, input, current_catalogue, previous_end_date)- @staticmethod+ @classmethoddef send_sale_toggle_notification(- manager, instance, input, catalogue, previous_end_date+ cls, manager, instance, input, catalogue, previous_end_date):"""Send the notification about starting or ending sale if it wasn't sent yet.@@ -251,6 +251,6 @@ class SaleUpdate(ModelMutation):send_notification = Trueif send_notification:- manager.sale_toggle(instance, catalogue)+ cls.call_event(manager.sale_toggle, instance, catalogue)instance.last_notification_scheduled_at = nowinstance.save(update_fields=["last_notification_scheduled_at"])diff --git a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_activate.py b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_activate.pyindex 69bbc46125..ea336f40ba 100644--- a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_activate.py+++ b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_activate.py@@ -60,4 +60,4 @@ class GiftCardBulkActivate(BaseBulkMutation):)manager = get_plugin_manager_promise(info.context).get()for card in models.GiftCard.objects.filter(id__in=gift_card_ids):- manager.gift_card_status_changed(card, webhooks=webhooks)+ cls.call_event(manager.gift_card_status_changed, card, webhooks=webhooks)diff --git a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_create.py b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_create.pyindex bd50b2ae11..876f1ebcae 100644--- a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_create.py+++ b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_create.py@@ -172,9 +172,9 @@ class GiftCardBulkCreate(BaseMutation):for tag_instance in tags_instances.iterator():tag_instance.gift_cards.set(instances)- @staticmethod- def call_gift_card_created_on_plugins(instances, context):+ @classmethod+ def call_gift_card_created_on_plugins(cls, instances, context):webhooks = get_webhooks_for_event(WebhookEventAsyncType.GIFT_CARD_CREATED)manager = get_plugin_manager_promise(context).get()for instance in instances:- manager.gift_card_created(instance, webhooks=webhooks)+ cls.call_event(manager.gift_card_created, instance, webhooks=webhooks)diff --git a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_deactivate.py b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_deactivate.pyindex 7cd3b0996b..2cbf705198 100644--- a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_deactivate.py+++ b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_deactivate.py@@ -51,4 +51,4 @@ class GiftCardBulkDeactivate(BaseBulkMutation):)manager = get_plugin_manager_promise(info.context).get()for card in models.GiftCard.objects.filter(id__in=gift_card_ids):- manager.gift_card_status_changed(card, webhooks=webhooks)+ cls.call_event(manager.gift_card_status_changed, card, webhooks=webhooks)diff --git a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_delete.py b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_delete.pyindex ed1ead37fb..6c04c5218f 100644--- a/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_delete.py+++ b/saleor/graphql/giftcard/bulk_mutations/gift_card_bulk_delete.py@@ -39,4 +39,4 @@ class GiftCardBulkDelete(ModelBulkDeleteMutation):webhooks = get_webhooks_for_event(WebhookEventAsyncType.GIFT_CARD_DELETED)manager = get_plugin_manager_promise(info.context).get()for instance in instances:- manager.gift_card_deleted(instance, webhooks=webhooks)+ cls.call_event(manager.gift_card_deleted, instance, webhooks=webhooks)diff --git a/saleor/graphql/menu/bulk_mutations/menu_bulk_delete.py b/saleor/graphql/menu/bulk_mutations/menu_bulk_delete.pyindex 80ab9a7c8f..c138546f8b 100644--- a/saleor/graphql/menu/bulk_mutations/menu_bulk_delete.py+++ b/saleor/graphql/menu/bulk_mutations/menu_bulk_delete.py@@ -39,4 +39,4 @@ class MenuBulkDelete(ModelBulkDeleteMutation):webhooks = get_webhooks_for_event(WebhookEventAsyncType.MENU_DELETED)manager = get_plugin_manager_promise(info.context).get()for menu in menus:- manager.menu_deleted(menu, webhooks=webhooks)+ cls.call_event(manager.menu_deleted, menu, webhooks=webhooks)diff --git a/saleor/graphql/menu/bulk_mutations/menu_item_bulk_delete.py b/saleor/graphql/menu/bulk_mutations/menu_item_bulk_delete.pyindex 3f9200f7cb..096e03629e 100644--- a/saleor/graphql/menu/bulk_mutations/menu_item_bulk_delete.py+++ b/saleor/graphql/menu/bulk_mutations/menu_item_bulk_delete.py@@ -39,4 +39,4 @@ class MenuItemBulkDelete(ModelBulkDeleteMutation):webhooks = get_webhooks_for_event(WebhookEventAsyncType.MENU_ITEM_DELETED)manager = get_plugin_manager_promise(info.context).get()for menu_item in menu_items:- manager.menu_item_deleted(menu_item, webhooks=webhooks)+ cls.call_event(manager.menu_item_deleted, menu_item, webhooks=webhooks)diff --git a/saleor/graphql/page/bulk_mutations.py b/saleor/graphql/page/bulk_mutations.pyindex cef5092abb..c609b0086b 100644--- a/saleor/graphql/page/bulk_mutations.py+++ b/saleor/graphql/page/bulk_mutations.py@@ -1,6 +1,5 @@import graphenefrom django.core.exceptions import ValidationError-from django.db import transactionfrom ...attribute import AttributeInputTypefrom ...attribute import models as attribute_models@@ -106,7 +105,7 @@ class PageTypeBulkDelete(ModelBulkDeleteMutation):queryset.delete()manager = get_plugin_manager_promise(info.context).get()for pt in page_types:- transaction.on_commit(lambda: manager.page_type_deleted(pt))+ cls.call_event(manager.page_type_deleted, pt)@staticmethoddef delete_assigned_attribute_values(instance_pks):diff --git a/saleor/graphql/product/bulk_mutations/collection_bulk_delete.py b/saleor/graphql/product/bulk_mutations/collection_bulk_delete.pyindex 0e1c90a984..8b2f02d12c 100644--- a/saleor/graphql/product/bulk_mutations/collection_bulk_delete.py+++ b/saleor/graphql/product/bulk_mutations/collection_bulk_delete.py@@ -40,12 +40,12 @@ class CollectionBulkDelete(ModelBulkDeleteMutation):manager = get_plugin_manager_promise(info.context).get()webhooks = get_webhooks_for_event(WebhookEventAsyncType.COLLECTION_DELETED)for collection in queryset.iterator():- manager.collection_deleted(collection, webhooks=webhooks)+ cls.call_event(manager.collection_deleted, collection, webhooks=webhooks)queryset.delete()webhooks = get_webhooks_for_event(WebhookEventAsyncType.PRODUCT_UPDATED)for product in products:- manager.product_updated(product, webhooks=webhooks)+ cls.call_event(manager.product_updated, product, webhooks=webhooks)update_products_discounted_prices_for_promotion_task.delay([product.id for product in products]diff --git a/saleor/graphql/product/bulk_mutations/product_bulk_delete.py b/saleor/graphql/product/bulk_mutations/product_bulk_delete.pyindex bc39bf7601..1cdee6cea2 100644--- a/saleor/graphql/product/bulk_mutations/product_bulk_delete.py+++ b/saleor/graphql/product/bulk_mutations/product_bulk_delete.py@@ -99,4 +99,6 @@ class ProductBulkDelete(ModelBulkDeleteMutation):manager = get_plugin_manager_promise(info.context).get()for product in products:variants = product_variant_map.get(product.id, [])- manager.product_deleted(product, variants, webhooks=webhooks)+ cls.call_event(+ manager.product_deleted, product, variants, webhooks=webhooks+ )diff --git a/saleor/graphql/product/bulk_mutations/product_variant_bulk_delete.py b/saleor/graphql/product/bulk_mutations/product_variant_bulk_delete.pyindex f3707897d2..c462500670 100644--- a/saleor/graphql/product/bulk_mutations/product_variant_bulk_delete.py+++ b/saleor/graphql/product/bulk_mutations/product_variant_bulk_delete.py@@ -2,7 +2,6 @@ from typing import Iterableimport graphenefrom django.core.exceptions import ValidationError-from django.db import transactionfrom django.db.models import Exists, OuterRef, Subqueryfrom django.db.models.fields import IntegerFieldfrom django.db.models.functions import Coalesce@@ -90,12 +89,8 @@ class ProductVariantBulkDelete(ModelBulkDeleteMutation):response = super().perform_mutation(_root, info, ids=ids, **data)manager = get_plugin_manager_promise(info.context).get()webhooks = get_webhooks_for_event(WebhookEventAsyncType.PRODUCT_VARIANT_DELETED)- transaction.on_commit(- lambda: [- manager.product_variant_deleted(variant, webhooks=webhooks)- for variant in variants- ]- )+ for variant in variants:+ cls.call_event(manager.product_variant_deleted, variant, webhooks=webhooks)# delete order lines for deleted variantsorder_models.OrderLine.objects.filter(diff --git a/saleor/graphql/product/bulk_mutations/product_variant_stocks_create.py b/saleor/graphql/product/bulk_mutations/product_variant_stocks_create.pyindex 99cb02d00f..bb0e8857cf 100644--- a/saleor/graphql/product/bulk_mutations/product_variant_stocks_create.py+++ b/saleor/graphql/product/bulk_mutations/product_variant_stocks_create.py@@ -3,7 +3,6 @@ from typing import Listimport graphenefrom django.core.exceptions import ValidationError-from django.db import transactionfrom ....core.tracing import traced_atomic_transactionfrom ....permission.enums import ProductPermissions@@ -67,10 +66,8 @@ class ProductVariantStocksCreate(BaseMutation):WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK)for stock in new_stocks:- transaction.on_commit(- lambda: manager.product_variant_back_in_stock(- stock, webhooks=webhooks- )+ cls.call_event(+ manager.product_variant_back_in_stock, stock, webhooks=webhooks)StocksWithAvailableQuantityByProductVariantIdCountryCodeAndChannelLoader(diff --git a/saleor/graphql/product/bulk_mutations/product_variant_stocks_delete.py b/saleor/graphql/product/bulk_mutations/product_variant_stocks_delete.pyindex 3f7ab5a899..93ab24e756 100644--- a/saleor/graphql/product/bulk_mutations/product_variant_stocks_delete.py+++ b/saleor/graphql/product/bulk_mutations/product_variant_stocks_delete.py@@ -1,6 +1,5 @@import graphenefrom django.core.exceptions import ValidationError-from django.db import transactionfrom ....core.tracing import traced_atomic_transactionfrom ....permission.enums import ProductPermissions@@ -80,8 +79,8 @@ class ProductVariantStocksDelete(BaseMutation):WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK)for stock in stocks_to_delete:- transaction.on_commit(- lambda: manager.product_variant_out_of_stock(stock, webhooks=webhooks)+ cls.call_event(+ manager.product_variant_out_of_stock, stock, webhooks=webhooks)stocks_to_delete.delete()diff --git a/saleor/graphql/product/bulk_mutations/product_variant_stocks_update.py b/saleor/graphql/product/bulk_mutations/product_variant_stocks_update.pyindex 4e55350a0c..b4d00d9275 100644--- a/saleor/graphql/product/bulk_mutations/product_variant_stocks_update.py+++ b/saleor/graphql/product/bulk_mutations/product_variant_stocks_update.py@@ -3,7 +3,6 @@ from typing import Listimport graphenefrom django.core.exceptions import ValidationError-from django.db import transactionfrom ....core.tracing import traced_atomic_transactionfrom ....permission.enums import ProductPermissions@@ -112,27 +111,27 @@ class ProductVariantStocksUpdate(ProductVariantStocksCreate):<= 0< stock_data["quantity"]):- transaction.on_commit(- lambda: manager.product_variant_back_in_stock(- stock, webhooks=webhooks_stock_in- )+ cls.call_event(+ manager.product_variant_back_in_stock,+ stock,+ webhooks=webhooks_stock_in,)if stock_data["quantity"] <= 0 or (stock_data["quantity"] - stock.quantity_allocated <= 0):- transaction.on_commit(- lambda: manager.product_variant_out_of_stock(- stock, webhooks=webhooks_stock_out- )+ cls.call_event(+ manager.product_variant_out_of_stock,+ stock,+ webhooks=webhooks_stock_out,)stock.quantity = stock_data["quantity"]stocks.append(stock)- transaction.on_commit(- lambda: manager.product_variant_stock_updated(- stock, webhooks=webhooks_stock_update- )+ cls.call_event(+ manager.product_variant_stock_updated,+ stock,+ webhooks=webhooks_stock_update,)warehouse_models.Stock.objects.bulk_update(stocks, ["quantity"])diff --git a/saleor/graphql/product/mutations/product_variant/product_variant_delete.py b/saleor/graphql/product/mutations/product_variant/product_variant_delete.pyindex 8d065ed940..f1fa9ba755 100644--- a/saleor/graphql/product/mutations/product_variant/product_variant_delete.py+++ b/saleor/graphql/product/mutations/product_variant/product_variant_delete.py@@ -137,7 +137,6 @@ class ProductVariantDelete(ModelDeleteMutation, ModelWithExtRefMutation):order_pks = draft_order_lines_data.order_pksif order_pks:recalculate_orders_task.delay(list(order_pks))-cls.call_event(manager.product_variant_deleted, variant)return responsediff --git a/saleor/graphql/product/tests/mutations/test_product_variant_stocks_update.py b/saleor/graphql/product/tests/mutations/test_product_variant_stocks_update.pyindex f506858295..7b3c6d7b41 100644--- a/saleor/graphql/product/tests/mutations/test_product_variant_stocks_update.py+++ b/saleor/graphql/product/tests/mutations/test_product_variant_stocks_update.py@@ -538,20 +538,14 @@ def test_update_or_create_variant_stocks_with_out_of_stock_webhook_only(]assert variant.stocks.aggregate(Sum("quantity"))["quantity__sum"] == 10-ProductVariantStocksUpdate.update_or_create_variant_stocks(variant, stocks_data, warehouses, plugins)-- assert variant.stocks.aggregate(Sum("quantity"))["quantity__sum"] == 2-flush_post_commit_hooks()+ assert variant.stocks.aggregate(Sum("quantity"))["quantity__sum"] == 2assert product_variant_stock_out_of_stock_webhook.call_count == 1assert product_variant_stock_update_webhook.call_count == 2- product_variant_stock_update_webhook.assert_called_with(- Stock.objects.last(), webhooks=[any_webhook]- )product_variant_back_in_stock_webhook.assert_not_called()diff --git a/saleor/graphql/shipping/bulk_mutations/shipping_price_bulk_delete.py b/saleor/graphql/shipping/bulk_mutations/shipping_price_bulk_delete.pyindex 7c2b666769..9ca7179267 100644--- a/saleor/graphql/shipping/bulk_mutations/shipping_price_bulk_delete.py+++ b/saleor/graphql/shipping/bulk_mutations/shipping_price_bulk_delete.py@@ -51,4 +51,4 @@ class ShippingPriceBulkDelete(ModelBulkDeleteMutation):webhooks = get_webhooks_for_event(WebhookEventAsyncType.SHIPPING_PRICE_DELETED)manager = get_plugin_manager_promise(info.context).get()for method in shipping_methods:- manager.shipping_price_deleted(method, webhooks=webhooks)+ cls.call_event(manager.shipping_price_deleted, method, webhooks=webhooks)diff --git a/saleor/graphql/shipping/bulk_mutations/shipping_zone_bulk_delete.py b/saleor/graphql/shipping/bulk_mutations/shipping_zone_bulk_delete.pyindex 3ee6474b9d..ba0cb325c7 100644--- a/saleor/graphql/shipping/bulk_mutations/shipping_zone_bulk_delete.py+++ b/saleor/graphql/shipping/bulk_mutations/shipping_zone_bulk_delete.py@@ -34,4 +34,4 @@ class ShippingZoneBulkDelete(ModelBulkDeleteMutation):webhooks = get_webhooks_for_event(WebhookEventAsyncType.SHIPPING_ZONE_DELETED)manager = get_plugin_manager_promise(info.context).get()for zone in zones:- manager.shipping_zone_deleted(zone, webhooks=webhooks)+ cls.call_event(manager.shipping_zone_deleted, zone, webhooks=webhooks)diff --git a/saleor/graphql/shop/mutations/shop_settings_update.py b/saleor/graphql/shop/mutations/shop_settings_update.pyindex 4ece24e518..c3366b31c2 100644--- a/saleor/graphql/shop/mutations/shop_settings_update.py+++ b/saleor/graphql/shop/mutations/shop_settings_update.py@@ -213,6 +213,6 @@ class ShopSettingsUpdate(BaseMutation):or instance.private_metadata != old_private_metadata):manager = get_plugin_manager_promise(info.context).get()- manager.shop_metadata_updated(instance)+ cls.call_event(manager.shop_metadata_updated, instance)return ShopSettingsUpdate(shop=Shop())diff --git a/saleor/graphql/webhook/mutations/event_delivery_retry.py b/saleor/graphql/webhook/mutations/event_delivery_retry.pyindex 620b066a6a..b6220145dc 100644--- a/saleor/graphql/webhook/mutations/event_delivery_retry.py+++ b/saleor/graphql/webhook/mutations/event_delivery_retry.py@@ -31,5 +31,5 @@ class EventDeliveryRetry(BaseMutation):only_type=EventDelivery,)manager = get_plugin_manager_promise(info.context).get()- manager.event_delivery_retry(delivery)+ cls.call_event(manager.event_delivery_retry, delivery)return EventDeliveryRetry(delivery=delivery)diff --git a/saleor/product/tests/test_category.py b/saleor/product/tests/test_category.pyindex 4f79ec293e..4c0836fe74 100644--- a/saleor/product/tests/test_category.py+++ b/saleor/product/tests/test_category.py@@ -1,6 +1,7 @@from unittest.mock import patchfrom ...plugins.manager import get_plugins_manager+from ...tests.utils import flush_post_commit_hooksfrom ..models import Categoryfrom ..utils import collect_categories_tree_products, delete_categories@@ -58,12 +59,16 @@ def test_delete_categories_trigger_product_updated_webhook(# givenmocked_get_webhooks_for_event.return_value = [any_webhook]settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]+parent = categories_tree_with_published_productschild = parent.children.first()product_list = [child.products.first(), parent.products.first()]+ # whendelete_categories([parent.pk], manager=get_plugins_manager())+ flush_post_commit_hooks()+ # thenassert not Category.objects.filter(id__in=[category.id for category in [parent, child]]).exists()diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.pyindex 80bff848f2..a3bda29a02 100644--- a/saleor/product/utils/__init__.py+++ b/saleor/product/utils/__init__.py@@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Dict, Iterable, List, Unionfrom ...core.taxes import TaxedMoney, zero_taxed_moneyfrom ...core.tracing import traced_atomic_transaction+from ...core.utils.events import call_eventfrom ...webhook.event_types import WebhookEventAsyncTypefrom ...webhook.utils import get_webhooks_for_eventfrom ..models import Product, ProductChannelListing@@ -58,10 +59,10 @@ def delete_categories(categories_ids: List[Union[str, int]], manager):categories.delete()webhooks = get_webhooks_for_event(WebhookEventAsyncType.CATEGORY_DELETED)for category in category_instances:- manager.category_deleted(category, webhooks=webhooks)+ call_event(manager.category_deleted, category, webhooks=webhooks)webhooks = get_webhooks_for_event(WebhookEventAsyncType.PRODUCT_UPDATED)for product in products:- manager.product_updated(product, webhooks=webhooks)+ call_event(manager.product_updated, product, webhooks=webhooks)update_products_discounted_prices_for_promotion_task.delay(product_ids=[product.id for product in products]