From 6c7744935d3d125e11651d910fd9136c59c4375d Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Sun, 28 Dec 2025 12:18:15 +0330 Subject: [PATCH] fix: Update async handling in send_shop_order_invoice_telegram_task for Celery compatibility --- backend/order/tasks.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/order/tasks.py b/backend/order/tasks.py index ecd2cdb..d50f0ca 100644 --- a/backend/order/tasks.py +++ b/backend/order/tasks.py @@ -161,8 +161,13 @@ def send_shop_order_invoice_telegram_task(shop_order_id, chat_id, bot_token): caption=f'فاکتور سفارش #{shop_order_id}\n{shop_order.shop.shop_name}' ) - # Run async function - asyncio.run(send_invoice()) + # Run async function - create new event loop for Celery context + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + loop.run_until_complete(send_invoice()) + finally: + loop.close() logging.info(f'Successfully sent shop order invoice {shop_order_id} to Telegram chat {chat_id}') return f'Invoice sent successfully to chat {chat_id}'