From 25e8c9f8fc4d2c66d5a1407d3de5c7402dc596da Mon Sep 17 00:00:00 2001 From: Fringg Date: Mon, 16 Feb 2026 09:23:22 +0300 Subject: [PATCH] fix: use sync context manager for structlog bound_contextvars bound_contextvars() returns a sync _GeneratorContextManager, not async. Using `async with` caused TypeError crashing all web API requests. --- app/middlewares/context_binding.py | 2 +- app/webapi/middleware.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/middlewares/context_binding.py b/app/middlewares/context_binding.py index 25181991..e727fcb6 100644 --- a/app/middlewares/context_binding.py +++ b/app/middlewares/context_binding.py @@ -23,5 +23,5 @@ class ContextVarsMiddleware(BaseMiddleware): ctx['username'] = event.from_user.username or '' if hasattr(event, 'chat') and event.chat: ctx['chat_id'] = event.chat.id - async with bound_contextvars(**ctx): + with bound_contextvars(**ctx): return await handler(event, data) diff --git a/app/webapi/middleware.py b/app/webapi/middleware.py index c12606c5..1ed2d26e 100644 --- a/app/webapi/middleware.py +++ b/app/webapi/middleware.py @@ -17,7 +17,7 @@ class RequestLoggingMiddleware(BaseHTTPMiddleware): """Логирование входящих запросов в административный API.""" async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response: - async with bound_contextvars(http_method=request.method, http_path=request.url.path): + with bound_contextvars(http_method=request.method, http_path=request.url.path): start = monotonic() response: Response | None = None try: