Skip to content

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

Fix passing args to update_variants_names

Marcin Gębalaf44618a82477
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
index 131fc0d915..8616a7e526 100644
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -147,8 +147,8 @@ class ProductTypeForm(forms.ModelForm):
return data
self.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 data
def check_if_variants_changed(self, has_variants):
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 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.py
index 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, ProductVariant
from .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.py
index 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_ext
from saleor.graphql.core.types import ReportingPeriod
from saleor.graphql.product.types import StockAvailability
from saleor.product.models import (
- Category, Collection, Product, ProductImage, ProductType, ProductVariant)
+ Attribute, Category, Collection, Product, ProductImage, ProductType,
+ ProductVariant)
from saleor.product.tasks import update_variants_names
from .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 == 1
def test_product_variants_by_ids(user_api_client, variant):
diff --git a/tests/settings.py b/tests/settings.py
index 3885e5a772..56a4f91e69 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -1,6 +1,8 @@
# pylint: disable=W0401, W0614
from saleor.settings import * # noqa
+CELERY_TASK_ALWAYS_EAGER = True
+
SECRET_KEY = 'NOTREALLY'
DEFAULT_CURRENCY = 'USD'