diff --git a/zerver/middleware.py b/zerver/middleware.py index 67b19f61030155..0d0c1a866dfba2 100644 --- a/zerver/middleware.py +++ b/zerver/middleware.py @@ -689,3 +689,7 @@ def process_request(self, request: HttpRequest) -> Optional[HttpResponse]: return response return None + + +class ZulipNoopMiddleware(MiddlewareMixin): + pass diff --git a/zproject/computed_settings.py b/zproject/computed_settings.py index 45949c06dcc987..9f2bcba1687a9a 100644 --- a/zproject/computed_settings.py +++ b/zproject/computed_settings.py @@ -159,7 +159,7 @@ # ... and with the hosts in REALM_HOSTS. ALLOWED_HOSTS += REALM_HOSTS.values() -MIDDLEWARE = ( +MIDDLEWARE = [ "zerver.middleware.TagRequests", "zerver.middleware.SetRemoteAddrFromRealIpHeader", "zerver.middleware.RequestContext", @@ -182,7 +182,7 @@ "two_factor.middleware.threadlocals.ThreadLocals", # Required by Twilio # Needs to be after CommonMiddleware, which sets Content-Length "zerver.middleware.FinalizeOpenGraphDescription", -) +] AUTH_USER_MODEL = "zerver.UserProfile" diff --git a/zproject/test_extra_settings.py b/zproject/test_extra_settings.py index be7a3d261b55df..02f5939eaa04ce 100644 --- a/zproject/test_extra_settings.py +++ b/zproject/test_extra_settings.py @@ -15,6 +15,7 @@ EXTERNAL_HOST, LOCAL_DATABASE_PASSWORD, LOGGING, + MIDDLEWARE, ) FULL_STACK_ZULIP_TEST = "FULL_STACK_ZULIP_TEST" in os.environ @@ -269,3 +270,13 @@ def set_loglevel(logger_name: str, level: str) -> None: "name_formatted_included": True, } } + + +while len(MIDDLEWARE) < 19: + # The following middleware serves to skip having exactly 17 or 18 + # middlewares, which can segfault Python 3.11 when running with + # coverage enabled; see + # https://github.com/python/cpython/issues/106092 + MIDDLEWARE += [ + "zerver.middleware.ZulipNoopMiddleware", + ]