summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/deprecation.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py
index caed5b25d4..19379dfe58 100644
--- a/django/utils/deprecation.py
+++ b/django/utils/deprecation.py
@@ -1,8 +1,7 @@
-import asyncio
import inspect
import warnings
-from asgiref.sync import sync_to_async
+from asgiref.sync import iscoroutinefunction, markcoroutinefunction, sync_to_async
class RemovedInDjango50Warning(DeprecationWarning):
@@ -120,16 +119,14 @@ class MiddlewareMixin:
If get_response is a coroutine function, turns us into async mode so
a thread is not consumed during a whole request.
"""
- if asyncio.iscoroutinefunction(self.get_response):
+ if iscoroutinefunction(self.get_response):
# Mark the class as async-capable, but do the actual switch
# inside __call__ to avoid swapping out dunder methods
- self._is_coroutine = asyncio.coroutines._is_coroutine
- else:
- self._is_coroutine = None
+ markcoroutinefunction(self)
def __call__(self, request):
# Exit out to async mode, if needed
- if self._is_coroutine:
+ if iscoroutinefunction(self):
return self.__acall__(request)
response = None
if hasattr(self, "process_request"):