﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34328	Class-based async-only middleware not detected as coroutine in MiddlewareMixin	Sergei	Carlton Gibson	"If an async middleware is implemented in class-based manner, other middleware in a chain may fail to recognize it as async. Stock Django middlewares use `MiddlewareMixin`, and it does not check for this kind of implementation.

This results in coroutines leaking to sync code, and `AttributeError`'s raised for accessing things like `.status_code` on a coroutine object instead of a response.

`MiddlewareMixin._async_check()` uses `asgiref.sync.iscoroutinefunction()` for checking.

Small example (Python 3.10):

{{{
#!python

>>> class TestMiddleware:
...     async def __call__(self, request):
...         pass

>>> import asgiref.sync
>>> import inspect
>>> t = TestMiddleware()
>>> asgiref.sync.iscoroutinefunction(t)
False
>>> inspect.iscoroutinefunction(t)
False
}}}"	Cleanup/optimization	closed	Documentation	4.1	Normal	fixed	middleware async asyncio MiddlewareMixin	Carlton Gibson	Ready for checkin	1	0	0	0	0	0
