Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix asynchronous tasks
akjanika38ea2515c24
diff --git a/saleor/checkout/views/summary.py b/saleor/checkout/views/summary.pyindex 1ecf445b2f..5edef009e0 100644--- a/saleor/checkout/views/summary.py+++ b/saleor/checkout/views/summary.py@@ -29,7 +29,7 @@ def create_order(checkout):create_history_entry(order=order, user=user, content=pgettext_lazy('Order status history entry', 'Order was placed'))- send_order_confirmation(order)+ send_order_confirmation.delay(order)return order, redirect('order:payment', token=order.token)diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 6d2eddbe54..0aa20192b3 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -38,7 +38,7 @@ class OrderNoteForm(forms.ModelForm):def send_confirmation_email(self):order = self.instance.order- send_note_confirmation(order)+ send_note_confirmation.delay(order.pk)class ManagePaymentForm(forms.Form):diff --git a/saleor/order/emails.py b/saleor/order/emails.pyindex 5e21235e71..84e300422d 100644--- a/saleor/order/emails.py+++ b/saleor/order/emails.py@@ -5,13 +5,13 @@ from django.urls import reversefrom templated_email import send_templated_mailfrom ..core.utils import build_absolute_uri+from .models import OrderCONFIRM_ORDER_TEMPLATE = 'source/order/confirm_order'CONFIRM_PAYMENT_TEMPLATE = 'source/order/payment/confirm_payment'CONFIRM_NOTE_TEMPLATE = 'source/order/note/confirm_note'-@shared_taskdef _send_confirmation(email, url, template, context=None):site = Site.objects.get_current()ctx = {@@ -28,24 +28,30 @@ def _send_confirmation(email, url, template, context=None):template_name=template)-def collect_data_for_email(order, template):++def collect_data_for_email(order_pk, template):+ order = Order.objects.get(pk=order_pk)email = order.get_user_current_email()url = build_absolute_uri(reverse('order:details', kwargs={'token': order.token}))return {'email': email, 'url': url, 'template': template}-def send_order_confirmation(order):- email_data = collect_data_for_email(order, CONFIRM_ORDER_TEMPLATE)+@shared_task+def send_order_confirmation(order_pk):+ order = Order.objects.get(pk=order_pk)+ email_data = collect_data_for_email(order_pk, CONFIRM_ORDER_TEMPLATE)email_data.update({'context': {'order': order}})- _send_confirmation.delay(**email_data)+ _send_confirmation(**email_data)-def send_payment_confirmation(order):- email_data = collect_data_for_email(order, CONFIRM_PAYMENT_TEMPLATE)- _send_confirmation.delay(**email_data)+@shared_task+def send_payment_confirmation(order_pk):+ email_data = collect_data_for_email(order_pk, CONFIRM_PAYMENT_TEMPLATE)+ _send_confirmation(**email_data)-def send_note_confirmation(order):- email_data = collect_data_for_email(order, CONFIRM_NOTE_TEMPLATE)- _send_confirmation.delay(**email_data)+@shared_task+def send_note_confirmation(order_pk):+ email_data = collect_data_for_email(order_pk, CONFIRM_NOTE_TEMPLATE)+ _send_confirmation(**email_data)diff --git a/saleor/order/signals.py b/saleor/order/signals.pyindex a1133e9117..443d1428f5 100644--- a/saleor/order/signals.py+++ b/saleor/order/signals.py@@ -17,7 +17,7 @@ def order_status_change(sender, instance, **kwargs):order=order,content=pgettext_lazy('Order status history entry', 'Order fully paid'))- send_order_confirmation(order)+ send_order_confirmation.delay(order.pk)try:analytics.report_order(order.tracking_client_id, order)except Exception:diff --git a/tests/test_asynchronous_tasks.py b/tests/test_asynchronous_tasks.pyindex ae55a61b42..89be58df0e 100644--- a/tests/test_asynchronous_tasks.py+++ b/tests/test_asynchronous_tasks.py@@ -6,11 +6,9 @@ from saleor.order.emails import (@pytest.mark.django_db@pytest.mark.integration[email protected](reason="It causes other tests to fail right now")def test_email_sending_asynchronously(transactional_db, celery_app, celery_worker, order_with_lines):- order = send_order_confirmation.delay(- '[email protected]', '/nowhere/to/go', order_with_lines.pk)- payment = send_payment_confirmation.delay('[email protected]', '/nowhere/')+ order = send_order_confirmation.delay(order_with_lines.pk)+ payment = send_payment_confirmation.delay(order_with_lines.pk)order.get()payment.get()diff --git a/tests/test_emails.py b/tests/test_emails.pyindex fffabb4c70..38f52111e3 100644--- a/tests/test_emails.py+++ b/tests/test_emails.py@@ -24,7 +24,7 @@ def test_send_emails('email': EMAIL,'url': URL,'template': template}):- fun(order)+ fun(order.pk)context = {'protocol': 'http','domain': DOMAIN,diff --git a/tests/test_order.py b/tests/test_order.pyindex 9c6eb87961..061eece28a 100644--- a/tests/test_order.py+++ b/tests/test_order.py@@ -186,7 +186,7 @@ def test_delivery_group_is_shipping_required_partially_required(def test_collect_data_for_email(order):template = Mock(spec=str)order.user_mail = '[email protected]'- email_data = collect_data_for_email(order, template)+ email_data = collect_data_for_email(order.pk, template)order_url = reverse('order:details', kwargs={'token': order.token})assert order_url in email_data['url']assert email_data['email'] == order.user_email