From 22eaa2f80a2d174cb9f232b6fda3d942cbb6f77b Mon Sep 17 00:00:00 2001 From: claude-dev Date: Sun, 8 Mar 2026 22:23:27 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20Database-locked-Fehler=20beim=20L=C3=B6s?= =?UTF-8?q?chen=20von=20Lagen=20behoben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PRAGMA busy_timeout=5000 in get_db() hinzugefügt (SQLite wartet bis zu 5s auf Lock-Freigabe) - Try/except im Delete-Endpoint: gibt HTTP 409 statt 500 bei Lock-Konflikt Co-Authored-By: Claude Opus 4.6 --- src/database.py | 1 + src/routers/incidents.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/database.py b/src/database.py index 0b62b6e..ff9790f 100644 --- a/src/database.py +++ b/src/database.py @@ -226,6 +226,7 @@ async def get_db() -> aiosqlite.Connection: db.row_factory = aiosqlite.Row await db.execute("PRAGMA journal_mode=WAL") await db.execute("PRAGMA foreign_keys=ON") + await db.execute("PRAGMA busy_timeout=5000") return db diff --git a/src/routers/incidents.py b/src/routers/incidents.py index 2d3d050..b05ab6a 100644 --- a/src/routers/incidents.py +++ b/src/routers/incidents.py @@ -218,8 +218,16 @@ async def delete_incident( detail="Nur der Ersteller kann diese Lage loeschen", ) - await db.execute("DELETE FROM incidents WHERE id = ?", (incident_id,)) - await db.commit() + try: + await db.execute("DELETE FROM incidents WHERE id = ?", (incident_id,)) + await db.commit() + except Exception as e: + if "database is locked" in str(e): + raise HTTPException( + status_code=status.HTTP_409_CONFLICT, + detail="Datenbank ist momentan beschaeftigt. Bitte in wenigen Sekunden erneut versuchen.", + ) + raise @router.get("/{incident_id}/articles")