Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix passing IDs instead of objects to Celery tasks
Marcin Gębala088965a20a6a
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.pyindex ca9779d227..c34e36999b 100644--- a/saleor/dashboard/customer/views.py+++ b/saleor/dashboard/customer/views.py@@ -61,7 +61,7 @@ def customer_create(request):form.save()msg = pgettext_lazy('Dashboard message', 'Added customer %s') % customer- send_set_password_email.delay(customer)+ send_set_password_email.delay(customer.pk)messages.success(request, msg)return redirect('dashboard:customer-details', pk=customer.pk)ctx = {'form': form, 'customer': customer}diff --git a/saleor/dashboard/emails.py b/saleor/dashboard/emails.pyindex 140bf7b638..7788abc624 100644--- a/saleor/dashboard/emails.py+++ b/saleor/dashboard/emails.py@@ -6,12 +6,14 @@ from django.utils.encoding import force_bytesfrom django.utils.http import urlsafe_base64_encodefrom templated_email import send_templated_mail+from ..account.models import Userfrom ..core.emails import get_email_base_contextfrom ..core.utils import build_absolute_uri@shared_task-def send_set_password_email(staff):+def send_set_password_email(staff_pk):+ staff = User.objects.get(pk=staff_pk)uid = urlsafe_base64_encode(force_bytes(staff.pk)).decode()token = default_token_generator.make_token(staff)password_set_url = build_absolute_uri(@@ -28,7 +30,8 @@ def send_set_password_email(staff):@shared_task-def send_promote_customer_to_staff_email(staff):+def send_promote_customer_to_staff_email(staff_pk):+ staff = User.objects.get(pk=staff_pk)ctx = get_email_base_context()ctx['dashboard_url'] = build_absolute_uri(reverse('dashboard:index'))send_templated_mail(diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.pyindex 6525b67a44..131fc0d915 100644--- a/saleor/dashboard/product/forms.py+++ b/saleor/dashboard/product/forms.py@@ -148,7 +148,7 @@ class ProductTypeForm(forms.ModelForm):self.check_if_variants_changed(has_variants)update_variants_names.delay(- self.instance, saved_attributes=variant_attr)+ self.instance.pk, saved_attributes=variant_attr)return datadef check_if_variants_changed(self, has_variants):diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.pyindex 4713fa0f2b..4b572ba224 100644--- a/saleor/dashboard/staff/views.py+++ b/saleor/dashboard/staff/views.py@@ -63,9 +63,9 @@ def staff_create(request):'Dashboard message', 'Added staff member %s') % (staff,)messages.success(request, msg)if created:- send_set_password_email.delay(staff)+ send_set_password_email.delay(staff.pk)else:- send_promote_customer_to_staff_email.delay(staff)+ send_promote_customer_to_staff_email.delay(staff.pk)return redirect('dashboard:staff-list')ctx = {'form': form}return TemplateResponse(request, 'dashboard/staff/detail.html', ctx)diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 055d7580ce..07314f944a 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -495,7 +495,7 @@ class ProductTypeUpdate(ProductTypeCreate):variant_attr = cleaned_input.get('variant_attributes')if variant_attr:variant_attr = set(variant_attr)- update_variants_names.delay(instance, variant_attr)+ update_variants_names.delay(instance.pk, variant_attr)super().save(info, instance, cleaned_input)diff --git a/saleor/product/tasks.py b/saleor/product/tasks.pyindex 24f06df43b..1ef53be3fc 100644--- a/saleor/product/tasks.py+++ b/saleor/product/tasks.py@@ -1,6 +1,6 @@from celery import shared_task-from .models import ProductVariant+from .models import ProductType, ProductVariantfrom .utils.attributes import get_name_from_attributes@@ -24,5 +24,6 @@ def _update_variants_names(instance, saved_attributes):@shared_task-def update_variants_names(instance, saved_attributes):+def update_variants_names(product_type_pk, saved_attributes):+ instance = ProductType.objects.get(pk=product_type_pk)return _update_variants_names(instance, saved_attributes)diff --git a/tests/api/test_product.py b/tests/api/test_product.pyindex e0841f3102..3b0883a72e 100644--- a/tests/api/test_product.py+++ b/tests/api/test_product.py@@ -1293,7 +1293,7 @@ def test_product_type_update_changes_variant_name(def test_product_update_variants_names(mock__update_variants_names,product_type):variant_attributes = [product_type.variant_attributes.first()]- update_variants_names(product_type, variant_attributes)+ update_variants_names(product_type.pk, variant_attributes)mock__update_variants_names.assert_called_once_with(product_type, variant_attributes)