Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
middleware: Reorder middleware to clean up LogRequests hasattr checks.
Zixuan James Li75925fe0597e
diff --git a/zerver/middleware.py b/zerver/middleware.pyindex 93c6f0e8519..a2655e9aff2 100644--- a/zerver/middleware.py+++ b/zerver/middleware.py@@ -420,7 +420,7 @@ class LogRequests(MiddlewareMixin):if requestor_for_logs is None:# Note that request.user is a Union[RemoteZulipServer, UserProfile, AnonymousUser],# if it is present.- if hasattr(request, "user") and hasattr(request.user, "format_requestor_for_logs"):+ if hasattr(request.user, "format_requestor_for_logs"):requestor_for_logs = request.user.format_requestor_for_logs()else:requestor_for_logs = "unauth@{}".format(get_subdomain(request) or "root")diff --git a/zproject/computed_settings.py b/zproject/computed_settings.pyindex c8a5ae426a2..556f427eac3 100644--- a/zproject/computed_settings.py+++ b/zproject/computed_settings.py@@ -166,19 +166,21 @@ class TwoFactorLoader(app_directories.Loader):MIDDLEWARE = (- # With the exception of it's dependencies,- # our logging middleware should be the top middleware item."zerver.middleware.TagRequests","zerver.middleware.SetRemoteAddrFromRealIpHeader","zerver.middleware.RequestContext",+ "django.contrib.sessions.middleware.SessionMiddleware",+ "django.contrib.auth.middleware.AuthenticationMiddleware",+ # Important: All middleware before LogRequests should be+ # inexpensive, because any time spent in that middleware will not+ # be counted in the LogRequests instrumentation of how time was+ # spent while processing a request."zerver.middleware.LogRequests","zerver.middleware.JsonErrorHandler","zerver.middleware.RateLimitMiddleware","zerver.middleware.FlushDisplayRecipientCache","zerver.middleware.ZulipCommonMiddleware",- "django.contrib.sessions.middleware.SessionMiddleware","zerver.middleware.LocaleMiddleware",- "django.contrib.auth.middleware.AuthenticationMiddleware","zerver.middleware.HostDomainMiddleware","django.middleware.csrf.CsrfViewMiddleware","zerver.middleware.ZulipSCIMAuthCheckMiddleware",