Changes between Version 6 and Version 9 of Ticket #33716


Ignore:
Timestamp:
05/18/22 02:33:26 (7 months ago)
Author:
abetkin
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33716 – Description

    v6 v9  
    1515}}}
    1616
    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?
     17This 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?
    1818
    19 A common usecase that is currently not supported:
     19The downside of _async_check is that this common usecase is not supported:
    2020
    2121
     
    3535middleware(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).
    3636
    37 So I propose to remove the redundant _async_check
     37Here is a patch that I use that explains a possible way to fix it:
    3838
    39 Github project to see the error: https://github.com/pwtail/django_bug
     39
     40{{{
     41def 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
     47MiddlewareMixin.__call__ = call_mw
     48}}}
     49
     50
     51Github project that shows the error: https://github.com/pwtail/django_bug
Back to Top