From 32d70b2f55b1f74736fd11bc8efce890ad5fa2f0 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 20 Dec 2022 11:10:48 +0100 Subject: Refs #34118 -- Adopted asgiref coroutine detection shims. Thanks to Mariusz Felisiak for review. --- docs/topics/http/middleware.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/topics/http') diff --git a/docs/topics/http/middleware.txt b/docs/topics/http/middleware.txt index 29f379889f..e1a3e95ebc 100644 --- a/docs/topics/http/middleware.txt +++ b/docs/topics/http/middleware.txt @@ -312,7 +312,7 @@ If your middleware has both ``sync_capable = True`` and ``async_capable = True``, then Django will pass it the request without converting it. In this case, you can work out if your middleware will receive async requests by checking if the ``get_response`` object you are passed is a -coroutine function, using ``asyncio.iscoroutinefunction``. +coroutine function, using ``asgiref.sync.iscoroutinefunction``. The ``django.utils.decorators`` module contains :func:`~django.utils.decorators.sync_only_middleware`, @@ -331,13 +331,13 @@ at an additional performance penalty. Here's an example of how to create a middleware function that supports both:: - import asyncio + from asgiref.sync import iscoroutinefunction from django.utils.decorators import sync_and_async_middleware @sync_and_async_middleware def simple_middleware(get_response): # One-time configuration and initialization goes here. - if asyncio.iscoroutinefunction(get_response): + if iscoroutinefunction(get_response): async def middleware(request): # Do something here! response = await get_response(request) -- cgit v1.3