Changes between Version 6 and Version 9 of Ticket #33716
- Timestamp:
- May 17, 2022, 9:33:26 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #33716 – Description
v6 v9 15 15 }}} 16 16 17 This checks if the next middleware is a coroutine, and if not fallbacks to sync mode. However, we already mark all async-capable middleware as such, why the redundancy?17 This checks if the next middleware is a coroutine, and if not fallbacks to sync mode. However, I think this check is redundant: if the middleware is async-capable, and we have an ASGI request, what else we need ti check? 18 18 19 A common usecase that is currentlynot supported:19 The downside of _async_check is that this common usecase is not supported: 20 20 21 21 … … 35 35 middleware(request) will return the response in sync case and a coroutine in the async case, despite being a regular function (because get_response is a coroutine function in the latter case). 36 36 37 So I propose to remove the redundant _async_check 37 Here is a patch that I use that explains a possible way to fix it: 38 38 39 Github project to see the error: https://github.com/pwtail/django_bug 39 40 {{{ 41 def call_mw(mw, request, _call_mw=MiddlewareMixin.__call__): 42 if isinstance(request, ASGIRequest) and mw.async_capable: 43 return mw.__acall__(request) 44 return _call_mw(mw, request) 45 46 47 MiddlewareMixin.__call__ = call_mw 48 }}} 49 50 51 Github project that shows the error: https://github.com/pwtail/django_bug