From 844dbf6a2254cf19f45ddce7e428bdcafd250a00 Mon Sep 17 00:00:00 2001 From: Paulo Victor Cordeiro <146781332+pvcordeiro@users.noreply.github.com> Date: Wed, 3 Jun 2026 06:12:00 +0100 Subject: [PATCH] fix: use safe .get for id lookup in uploads.json to prevent KeyError (#1465) When uploads.json contains a malformed entry without an 'id' key, the file-serve and lookup helpers crash with KeyError instead of gracefully skipping the entry. --- routes/upload_routes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/upload_routes.py b/routes/upload_routes.py index d45ff5c..4f55b50 100644 --- a/routes/upload_routes.py +++ b/routes/upload_routes.py @@ -111,7 +111,7 @@ def setup_upload_routes(upload_handler): if os.path.exists(uploads_db): with open(uploads_db, encoding="utf-8") as f: db = json.load(f) - info = next((fi for fi in db.values() if fi["id"] == file_id), None) + info = next((fi for fi in db.values() if fi.get("id") == file_id), None) if info: original_name = info.get("name", file_id) auth_mgr = getattr(request.app.state, "auth_manager", None) @@ -159,7 +159,7 @@ def setup_upload_routes(upload_handler): if os.path.exists(uploads_db): with open(uploads_db, encoding="utf-8") as f: db = json.load(f) - info = next((fi for fi in db.values() if fi["id"] == file_id), None) + info = next((fi for fi in db.values() if fi.get("id") == file_id), None) return info def _vision_cache_path(file_id: str) -> str: