From 2c52bede011c759c802e56c484405b6a93619502 Mon Sep 17 00:00:00 2001 From: FWao Date: Fri, 7 Aug 2026 10:14:35 +0200 Subject: [PATCH] Clear the remaining CodeQL alerts --- backend/src/main.py | 5 ++--- backend/tests/integration/test_api.py | 9 +++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/main.py b/backend/src/main.py index 28a037b..e058007 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -5,7 +5,7 @@ import asyncio import logging -from contextlib import asynccontextmanager, suppress +from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware @@ -57,8 +57,7 @@ async def lifespan(app: FastAPI): yield finally: sweeper.cancel() - with suppress(asyncio.CancelledError): - await sweeper + await asyncio.gather(sweeper, return_exceptions=True) # Nothing outlives the process, and nothing waits for a TTL either. request_cache.clear() diff --git a/backend/tests/integration/test_api.py b/backend/tests/integration/test_api.py index 0b8a46d..193fc24 100644 --- a/backend/tests/integration/test_api.py +++ b/backend/tests/integration/test_api.py @@ -303,13 +303,12 @@ def test_extension_is_bounded_by_the_configured_ceiling(client, monkeypatch): 12-hour day.""" import backend.src.utils.cache as cache_module from backend.src.core.config import get_settings - from backend.src.utils.cache import request_cache monkeypatch.setenv("RESULT_CACHE_TTL_MINUTES", "15") monkeypatch.setenv("RESULT_CACHE_EXTENSION_MINUTES", "60") monkeypatch.setenv("RESULT_CACHE_MAX_LIFETIME_MINUTES", "30") get_settings.cache_clear() - request_cache.configure(get_settings()) # what the app's lifespan does + cache_module.request_cache.configure(get_settings()) # what the app's lifespan does clock = {"now": 1000.0} monkeypatch.setattr(cache_module.time, "monotonic", lambda: clock["now"]) @@ -338,7 +337,8 @@ def test_delete_forgets_the_cached_document(client): first = client.post("/api/v1/anonymize", json={"text": SAMPLE_TEXT}).json() request_id = first["request_id"] - assert client.delete(f"/api/v1/anonymize/{request_id}").status_code == 204 + deleted = client.delete(f"/api/v1/anonymize/{request_id}") + assert deleted.status_code == 204 # The document is gone: a re-run now has nothing to work from. rerun = client.post("/api/v1/anonymize", json={"request_id": request_id, "overrides": []}) assert rerun.status_code == 410 @@ -347,7 +347,8 @@ def test_delete_forgets_the_cached_document(client): def test_delete_of_an_unknown_id_reveals_nothing(client): """Same answer either way — whether an id exists is not something an unrelated caller should be able to probe.""" - assert client.delete("/api/v1/anonymize/no-such-id").status_code == 204 + deleted = client.delete("/api/v1/anonymize/no-such-id") + assert deleted.status_code == 204 def test_request_id_is_not_written_to_the_log(client, caplog):