1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #33495 -- Improved debug logging message about adapting handlers for middlewares.

It's the wrapped handler that's adapted to the wrapping middleware.
This commit is contained in:
Aaron Chong 2022-02-09 01:25:33 +08:00 committed by Mariusz Felisiak
parent d35ce682e3
commit 2d472ad05c
3 changed files with 11 additions and 12 deletions

View File

@ -125,11 +125,11 @@ class BaseHandler:
if is_async:
if not method_is_async:
if debug:
logger.debug("Synchronous %s adapted.", name)
logger.debug("Synchronous handler adapted for %s.", name)
return sync_to_async(method, thread_sensitive=True)
elif method_is_async:
if debug:
logger.debug("Asynchronous %s adapted.", name)
logger.debug("Asynchronous handler adapted for %s.", name)
return async_to_sync(method)
return method

View File

@ -52,9 +52,9 @@ If you want to use these, you will need to deploy Django using
Middleware can be built to support :ref:`both sync and async
<async-middleware>` contexts. Some of Django's middleware is built like
this, but not all. To see what middleware Django has to adapt, you can turn
on debug logging for the ``django.request`` logger and look for log
messages about *"Synchronous middleware ... adapted"*.
this, but not all. To see what middleware Django has to adapt for, you can
turn on debug logging for the ``django.request`` logger and look for log
messages about *"Asynchronous handler adapted for middleware ..."*.
In both ASGI and WSGI mode, you can still safely use asynchronous support to
run code concurrently rather than serially. This is especially handy when

View File

@ -222,8 +222,8 @@ class MiddlewareNotUsedTests(SimpleTestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(
cm.records[0].getMessage(),
"Asynchronous middleware middleware_exceptions.tests.MyMiddleware "
"adapted.",
"Asynchronous handler adapted for middleware "
"middleware_exceptions.tests.MyMiddleware.",
)
self.assertEqual(
cm.records[1].getMessage(),
@ -265,9 +265,8 @@ class MiddlewareSyncAsyncTests(SimpleTestCase):
self.assertEqual(response.status_code, 402)
self.assertEqual(
cm.records[0].getMessage(),
"Synchronous middleware "
"middleware_exceptions.middleware.async_payment_middleware "
"adapted.",
"Synchronous handler adapted for middleware "
"middleware_exceptions.middleware.async_payment_middleware.",
)
@override_settings(
@ -295,8 +294,8 @@ class MiddlewareSyncAsyncTests(SimpleTestCase):
self.assertEqual(response.status_code, 402)
self.assertEqual(
cm.records[0].getMessage(),
"Asynchronous middleware "
"middleware_exceptions.middleware.PaymentMiddleware adapted.",
"Asynchronous handler adapted for middleware "
"middleware_exceptions.middleware.PaymentMiddleware.",
)
@override_settings(