From eb7c0a7076568aad5ecfd7c01a09a558623ffc01 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 6 Apr 2021 08:03:43 +0200 Subject: [PATCH] [3.2.x] Fixed #32614 -- Fixed MiddlewareSyncAsyncTests tests with asgiref 3.3.2+. Backport of 78fea27f690028204c03c28d821cb0c0240a7398 from main --- tests/middleware_exceptions/middleware.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/middleware_exceptions/middleware.py b/tests/middleware_exceptions/middleware.py index 9fb9726b50c..b87da84b9df 100644 --- a/tests/middleware_exceptions/middleware.py +++ b/tests/middleware_exceptions/middleware.py @@ -1,3 +1,5 @@ +import asyncio + from django.http import Http404, HttpResponse from django.template import engines from django.template.response import TemplateResponse @@ -11,6 +13,9 @@ log = [] class BaseMiddleware: def __init__(self, get_response): self.get_response = get_response + if asyncio.iscoroutinefunction(self.get_response): + # Mark the class as async-capable. + self._is_coroutine = asyncio.coroutines._is_coroutine def __call__(self, request): return self.get_response(request)