Skip to content

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

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.py
new file mode 100644
index 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.py
index 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.task
def handle_promotion_toggle():
"""Send the notification about promotion toggle and recalculate discounted prices.
diff --git a/saleor/product/tasks.py b/saleor/product/tasks.py
index 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, List
from uuid import UUID
from celery.utils.log import get_task_logger
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
-from django.db.models import Exists, OuterRef, Q
from django.utils import timezone
from ..attribute.models import Attribute
from ..celeryconf import app
from ..core.exceptions import PreorderAllocationError
from ..discount.models import Promotion
-from ..product.models import Category, CollectionProduct
from ..warehouse.management import deactivate_preorder_for_variant
from .models import Product, ProductType, ProductVariant
from .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.task
def update_products_discounted_prices_of_promotion_task(promotion_pk: UUID):
from ..graphql.discount.utils import get_products_for_promotion
diff --git a/saleor/product/tests/deprecated/__init__.py b/saleor/product/tests/deprecated/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/saleor/product/tests/deprecated/test_tasks.py b/saleor/product/tests/deprecated/test_tasks.py
deleted file mode 100644
index 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