Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Drop sale tables and celery tasks (#14277)
Iga Karbowiakfbab04ace778
diff --git a/saleor/discount/migrations/0055_drop_sales_from_db.py b/saleor/discount/migrations/0055_drop_sales_from_db.pynew file mode 100644index 0000000000..15d0a44003--- /dev/null+++ b/saleor/discount/migrations/0055_drop_sales_from_db.py@@ -0,0 +1,27 @@+# Generated by Django 3.2.22 on 2023-10-12 12:46++from django.db import migrations+++class Migration(migrations.Migration):+ dependencies = [+ ("discount", "0054_drop_sales_models"),+ ]++ operations = [+ migrations.SeparateDatabaseAndState(+ database_operations=[+ migrations.RunSQL(+ sql="""+ DROP TABLE discount_sale_categories;+ DROP TABLE discount_sale_collections;+ DROP TABLE discount_sale_products;+ DROP TABLE discount_sale_variants;+ DROP TABLE discount_salechannellisting;+ DROP TABLE discount_saletranslation;+ DROP TABLE discount_sale;+ """,+ ),+ ]+ )+ ]diff --git a/saleor/discount/tasks.py b/saleor/discount/tasks.pyindex 79108cc407..8157d01118 100644--- a/saleor/discount/tasks.py+++ b/saleor/discount/tasks.py@@ -20,12 +20,6 @@ if TYPE_CHECKING:task_logger = get_task_logger(__name__)-# DEPRECATED: To remove in 3.18-def handle_sale_toggle():- pass--@app.taskdef handle_promotion_toggle():"""Send the notification about promotion toggle and recalculate discounted prices.diff --git a/saleor/product/tasks.py b/saleor/product/tasks.pyindex b23f9cef66..04f7aba8a8 100644--- a/saleor/product/tasks.py+++ b/saleor/product/tasks.py@@ -1,18 +1,16 @@import logging-from typing import Iterable, List, Optional+from typing import Iterable, Listfrom uuid import UUIDfrom celery.utils.log import get_task_loggerfrom django.conf import settingsfrom django.core.exceptions import ObjectDoesNotExist-from django.db.models import Exists, OuterRef, Qfrom django.utils import timezonefrom ..attribute.models import Attributefrom ..celeryconf import appfrom ..core.exceptions import PreorderAllocationErrorfrom ..discount.models import Promotion-from ..product.models import Category, CollectionProductfrom ..warehouse.management import deactivate_preorder_for_variantfrom .models import Product, ProductType, ProductVariantfrom .search import PRODUCTS_BATCH_SIZE, update_products_search_vector@@ -76,61 +74,6 @@ def update_variants_names(product_type_pk: int, saved_attributes_ids: List[int])_update_variants_names(instance, saved_attributes)-# DEPRECATED: To remove in 3.18-def update_product_discounted_price_task(product_pk: int):- products = Product.objects.filter(pk=product_pk)- if not products:- logging.warning(f"Cannot find product with id: {product_pk}.")- return- update_discounted_prices_for_promotion(products)---# DEPRECATED: To remove in 3.18-def update_products_discounted_prices_of_catalogues_task(- product_ids: Optional[List[int]] = None,- category_ids: Optional[List[int]] = None,- collection_ids: Optional[List[int]] = None,- variant_ids: Optional[List[int]] = None,-):- lookup = Q()- if product_ids:- lookup |= Q(pk__in=product_ids)- if category_ids:- categories = Category.objects.filter(id__in=category_ids)- lookup |= Q(Exists(categories.filter(id=OuterRef("category_id"))))- if collection_ids:- collection_products = CollectionProduct.objects.filter(- collection_id__in=collection_ids- )- lookup |= Q(Exists(collection_products.filter(product_id=OuterRef("id"))))- if variant_ids:- lookup |= Q(Exists(ProductVariant.objects.filter(product_id=OuterRef("id"))))-- if lookup:- products = Product.objects.filter(lookup)- update_discounted_prices_for_promotion(products)---# DEPRECATED: To remove in 3.18-def update_products_discounted_prices_of_sale_task(discount_pk: int):- try:- promotion = Promotion.objects.get(old_sale_id=discount_pk)- except ObjectDoesNotExist:- logging.warning(f"Cannot find discount with id: {discount_pk}.")- return- update_products_discounted_prices_of_promotion_task(promotion.id)---# DEPRECATED: To remove in 3.18-def update_products_discounted_prices_task(product_ids: List[int]):- products = Product.objects.filter(pk__in=product_ids)- update_discounted_prices_for_promotion(products)--@app.taskdef update_products_discounted_prices_of_promotion_task(promotion_pk: UUID):from ..graphql.discount.utils import get_products_for_promotiondiff --git a/saleor/product/tests/deprecated/__init__.py b/saleor/product/tests/deprecated/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/product/tests/deprecated/test_tasks.py b/saleor/product/tests/deprecated/test_tasks.pydeleted file mode 100644index ac9de0ce6d..0000000000--- a/saleor/product/tests/deprecated/test_tasks.py+++ /dev/null@@ -1,103 +0,0 @@-import logging-from unittest.mock import patch--import graphene--from ...tasks import (- update_product_discounted_price_task,- update_products_discounted_prices_of_sale_task,-)---@patch(- "saleor.product.tasks.update_products_discounted_prices_for_promotion_task.delay"-)-def test_update_products_discounted_prices_of_sale_task(- update_discounted_prices_for_promotion_mock,- promotion_converted_from_sale_with_empty_predicate,- product_list,- product,- category,- collection,-):- # given- promotion = promotion_converted_from_sale_with_empty_predicate- collection_id = graphene.Node.to_global_id("Collection", collection.id)- category_id = graphene.Node.to_global_id("Category", category.id)- product_id = graphene.Node.to_global_id("Product", product.id)- variant_id = graphene.Node.to_global_id(- "ProductVariant", product_list[2].variants.first().id- )-- category.products.add(product_list[0])- collection.products.add(product_list[1])-- predicate = {- "OR": [- {"collectionPredicate": {"ids": [collection_id]}},- {"categoryPredicate": {"ids": [category_id]}},- {"productPredicate": {"ids": [product_id]}},- {"variantPredicate": {"ids": [variant_id]}},- ]- }- rule = promotion.rules.first()- rule.catalogue_predicate = predicate- rule.save(update_fields=["catalogue_predicate"])-- # when- update_products_discounted_prices_of_sale_task(promotion.old_sale_id)-- # then- update_discounted_prices_for_promotion_mock.assert_called_once()- args, kwargs = update_discounted_prices_for_promotion_mock.call_args-- expected_products = [product] + product_list- assert len(args[0]) == len(expected_products)- assert set(args[0]) == {instance.id for instance in expected_products}---@patch(- "saleor.product.tasks.update_products_discounted_prices_for_promotion_task.delay"-)-def test_update_products_discounted_prices_of_sale_task_discount_does_not_exist(- update_discounted_prices_for_promotion_mock, caplog-):- # given- caplog.set_level(logging.WARNING)- discount_id = -1-- # when- update_products_discounted_prices_of_sale_task(discount_id)-- # then- update_discounted_prices_for_promotion_mock.assert_not_called()- assert f"Cannot find discount with id: {discount_id}" in caplog.text---@patch("saleor.product.tasks.update_discounted_prices_for_promotion")-def test_update_product_discounted_price_task(- update_discounted_prices_for_promotion_mock, product-):- # when- update_product_discounted_price_task(product.id)-- # then- update_discounted_prices_for_promotion_mock.assert_called_once()- args, kwargs = update_discounted_prices_for_promotion_mock.call_args- assert args[0][0].id == product.id---@patch("saleor.product.tasks.update_discounted_prices_for_promotion")-def test_update_product_discounted_price_task_product_does_not_exist(- update_discounted_prices_for_promotion_mock, caplog-):- # given- caplog.set_level(logging.WARNING)- product_id = -1-- # when- update_product_discounted_price_task(product_id)-- # then- update_discounted_prices_for_promotion_mock.assert_not_called()- assert f"Cannot find product with id: {product_id}" in caplog.text