diff options
author | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-12-20 11:10:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-20 11:10:48 +0100 |
commit | 32d70b2f55b1f74736fd11bc8efce890ad5fa2f0 (patch) | |
tree | d88822bb2391e7cf4fdbda59b9f222839aeb7e93 /django/utils | |
parent | a09d39f28609c707a62dbbbdc4e55489fae1631f (diff) | |
download | django-32d70b2f55b1f74736fd11bc8efce890ad5fa2f0.tar.gz |
Refs #34118 -- Adopted asgiref coroutine detection shims.
Thanks to Mariusz Felisiak for review.
Diffstat (limited to 'django/utils')
-rw-r--r-- | django/utils/deprecation.py | 11 |
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"): |