Skip to content

Commit 9dac411

Browse files
committed
Add warning async is not supported
1 parent 2134600 commit 9dac411

File tree

2 files changed

+156
-93
lines changed

2 files changed

+156
-93
lines changed

debug_toolbar/middleware.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
from debug_toolbar.toolbar import DebugToolbar
1414
from debug_toolbar.utils import clear_stack_trace_caches
1515

16+
try:
17+
from django.core.handlers.asgi import ASGIRequest
18+
except ImportError:
19+
ASGIRequest = None
20+
1621
_HTML_TYPES = ("text/html", "application/xhtml+xml")
1722

1823

@@ -64,6 +69,10 @@ def __call__(self, request):
6469
if not show_toolbar(request) or DebugToolbar.is_toolbar_request(request):
6570
return self.get_response(request)
6671

72+
if self._check_async_request(request):
73+
self._show_async_request_is_not_supported()
74+
return self.get_response(request)
75+
6776
toolbar = DebugToolbar(request, self.get_response)
6877

6978
# Activate instrumentation ie. monkey-patch.
@@ -124,3 +133,12 @@ def get_headers(request, panels):
124133
else:
125134
headers[header] = value
126135
return headers
136+
137+
def _check_async_request(self, request) -> bool:
138+
return type(request) == ASGIRequest
139+
140+
@staticmethod
141+
def _show_async_request_is_not_supported():
142+
print('-' * 10)
143+
print('Be caution, django-debug-toolbar does not support async requests!')
144+
print('-' * 10)

0 commit comments

Comments
 (0)