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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user