Django 5 信号 asend:不可散列类型列表

问题描述 投票:0回答:1

尝试使用 django 5 异步信号制作一个简短的示例。这是代码:

查看:

async def confirm_email_async(request, code):
    await user_registered_async.asend(
        sender=User,
    )
    return JsonResponse({"status": "ok"})

信号:

user_registered_async = Signal()

@receiver(user_registered_async)
async def async_send_welcome_email(sender, **kwargs):
    print("Sending welcome email...")
    await asyncio.sleep(5)
    print("Email sent")

错误轨迹是:

Traceback (most recent call last):
  File "C:\Users\karonator\AppData\Roaming\Python\Python311\site-packages\asgiref\sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "C:\Users\karonator\AppData\Roaming\Python\Python311\site-packages\django\core\handlers\exception.py", line 42, in inner
    response = await get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\karonator\AppData\Roaming\Python\Python311\site-packages\asgiref\sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "C:\Users\karonator\AppData\Roaming\Python\Python311\site-packages\django\core\handlers\base.py", line 253, in _get_response_async
    response = await wrapped_callback(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\karonator\Desktop\signals\main\views.py", line 34, in confirm_email_async
    await user_registered_async.asend(
  File "C:\Users\karonator\AppData\Roaming\Python\Python311\site-packages\django\dispatch\dispatcher.py", line 250, in asend
    responses, async_responses = await asyncio.gather(
                                       ^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\asyncio\tasks.py", line 819, in gather
    if arg not in arg_to_fut:
       ^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'list'

将感谢任何帮助,已经伤透了我的头。 感谢您的宝贵时间。

python django python-asyncio django-signals
1个回答
0
投票

此处拼写错误

asend
send

更正

查看

async def confirm_email_async(request, code):
    await user_registered_async.send(sender=User)
    return JsonResponse({"status": "ok"})
© www.soinside.com 2019 - 2024. All rights reserved.