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/views | |
| parent | a09d39f28609c707a62dbbbdc4e55489fae1631f (diff) | |
Refs #34118 -- Adopted asgiref coroutine detection shims.
Thanks to Mariusz Felisiak for review.
Diffstat (limited to 'django/views')
| -rw-r--r-- | django/views/generic/base.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/django/views/generic/base.py b/django/views/generic/base.py index 3a3afb0c73..8f8f9397e8 100644 --- a/django/views/generic/base.py +++ b/django/views/generic/base.py @@ -1,6 +1,7 @@ -import asyncio import logging +from asgiref.sync import iscoroutinefunction, markcoroutinefunction + from django.core.exceptions import ImproperlyConfigured from django.http import ( HttpResponse, @@ -68,8 +69,8 @@ class View: ] if not handlers: return False - is_async = asyncio.iscoroutinefunction(handlers[0]) - if not all(asyncio.iscoroutinefunction(h) == is_async for h in handlers[1:]): + is_async = iscoroutinefunction(handlers[0]) + if not all(iscoroutinefunction(h) == is_async for h in handlers[1:]): raise ImproperlyConfigured( f"{cls.__qualname__} HTTP handlers must either be all sync or all " "async." @@ -117,7 +118,7 @@ class View: # Mark the callback if the view class is async. if cls.view_is_async: - view._is_coroutine = asyncio.coroutines._is_coroutine + markcoroutinefunction(view) return view |
