Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix passing args to update_variants_names
Marcin Gębalaf44618a82477
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.pyindex 131fc0d915..8616a7e526 100644--- a/saleor/dashboard/product/forms.py+++ b/saleor/dashboard/product/forms.py@@ -147,8 +147,8 @@ class ProductTypeForm(forms.ModelForm):return dataself.check_if_variants_changed(has_variants)- update_variants_names.delay(- self.instance.pk, saved_attributes=variant_attr)+ variant_attr_ids = [attr.pk for attr in variant_attr]+ update_variants_names.delay(self.instance.pk, variant_attr_ids)return datadef check_if_variants_changed(self, has_variants):diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 07314f944a..e546ab8e18 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -495,7 +495,8 @@ class ProductTypeUpdate(ProductTypeCreate):variant_attr = cleaned_input.get('variant_attributes')if variant_attr:variant_attr = set(variant_attr)- update_variants_names.delay(instance.pk, variant_attr)+ variant_attr_ids = [attr.pk for attr in variant_attr]+ update_variants_names.delay(instance.pk, variant_attr_ids)super().save(info, instance, cleaned_input)diff --git a/saleor/product/tasks.py b/saleor/product/tasks.pyindex 1ef53be3fc..d27548b18d 100644--- a/saleor/product/tasks.py+++ b/saleor/product/tasks.py@@ -1,6 +1,6 @@from celery import shared_task-from .models import ProductType, ProductVariant+from .models import Attribute, ProductType, ProductVariantfrom .utils.attributes import get_name_from_attributes@@ -24,6 +24,7 @@ def _update_variants_names(instance, saved_attributes):@shared_task-def update_variants_names(product_type_pk, saved_attributes):+def update_variants_names(product_type_pk, saved_attributes_ids):instance = ProductType.objects.get(pk=product_type_pk)+ saved_attributes = Attribute.objects.filter(pk__in=saved_attributes_ids)return _update_variants_names(instance, saved_attributes)diff --git a/tests/api/test_product.py b/tests/api/test_product.pyindex 3b0883a72e..2ee1068235 100644--- a/tests/api/test_product.py+++ b/tests/api/test_product.py@@ -11,7 +11,8 @@ from tests.utils import create_image, create_pdf_file_with_image_extfrom saleor.graphql.core.types import ReportingPeriodfrom saleor.graphql.product.types import StockAvailabilityfrom saleor.product.models import (- Category, Collection, Product, ProductImage, ProductType, ProductVariant)+ Attribute, Category, Collection, Product, ProductImage, ProductType,+ ProductVariant)from saleor.product.tasks import update_variants_namesfrom .utils import assert_no_permission, get_multipart_request_body@@ -1285,17 +1286,18 @@ def test_product_type_update_changes_variant_name(query, variables, permissions=[permission_manage_products])content = get_graphql_content(response)variant_attributes = set(variant_attributes)+ variant_attributes_ids = [attr.pk for attr in variant_attributes]mock_update_variants_names.assert_called_once_with(- product_type, variant_attributes)+ product_type.pk, variant_attributes_ids)@patch('saleor.product.tasks._update_variants_names')def test_product_update_variants_names(mock__update_variants_names,product_type):variant_attributes = [product_type.variant_attributes.first()]- update_variants_names(product_type.pk, variant_attributes)- mock__update_variants_names.assert_called_once_with(- product_type, variant_attributes)+ variant_attr_ids = [attr.pk for attr in variant_attributes]+ update_variants_names(product_type.pk, variant_attr_ids)+ mock__update_variants_names.call_count == 1def test_product_variants_by_ids(user_api_client, variant):diff --git a/tests/settings.py b/tests/settings.pyindex 3885e5a772..56a4f91e69 100644--- a/tests/settings.py+++ b/tests/settings.py@@ -1,6 +1,8 @@# pylint: disable=W0401, W0614from saleor.settings import * # noqa+CELERY_TASK_ALWAYS_EAGER = True+SECRET_KEY = 'NOTREALLY'DEFAULT_CURRENCY = 'USD'