Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
middleware: Add isinstance check before retrieving content.
Zixuan James Lie665ec8ae2c9
diff --git a/zerver/middleware.py b/zerver/middleware.pyindex d5b24857ee3..571eae57300 100644--- a/zerver/middleware.py+++ b/zerver/middleware.py@@ -2,18 +2,7 @@ import cProfileimport loggingimport timeimport traceback-from typing import (- Any,- AnyStr,- Callable,- Dict,- Iterable,- Iterator,- List,- MutableMapping,- Optional,- Tuple,-)+from typing import Any, AnyStr, Callable, Dict, Iterable, List, MutableMapping, Optional, Tuplefrom urllib.parse import urlencodefrom django.conf import settings@@ -425,13 +414,10 @@ class LogRequests(MiddlewareMixin):else:requestor_for_logs = "unauth@{}".format(get_subdomain(request) or "root")- if response.streaming:- assert isinstance(response, StreamingHttpResponse)- content_iter: Optional[Iterator[bytes]] = response.streaming_content- content = None- else:- content = response.content- content_iter = None+ content_iter = (+ response.streaming_content if isinstance(response, StreamingHttpResponse) else None+ )+ content = response.content if isinstance(response, HttpResponse) else Noneassert request_notes.client_name is not None and request_notes.log_data is not Noneassert request.method is not None