logging_util: Remove dependence on get_current_request.

Pass the HttpRequest explicitly through the two webhooks that log to
the webhook loggers.

get_current_request is now unused, so remove it (in the same commit
for test coverage reasons).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 63be67af80)
This commit is contained in:
Anders Kaseorg
2023-07-10 16:17:30 -04:00
committed by Alex Vandiver
parent cc21dc8ec7
commit 406f9f7852
9 changed files with 85 additions and 95 deletions

View File

@@ -11,6 +11,7 @@ from typing import Optional, Tuple, Union
import orjson
from django.conf import settings
from django.core.cache import cache
from django.http import HttpRequest
from django.utils.timezone import now as timezone_now
@@ -217,10 +218,8 @@ class ZulipWebhookFormatter(ZulipFormatter):
return "\n".join(multiline)
def format(self, record: logging.LogRecord) -> str:
from zerver.lib.request import get_current_request
request = get_current_request()
if not request:
request: Optional[HttpRequest] = getattr(record, "request", None)
if request is None:
record.user = None
record.client = None
record.url = None