From 522a0c5e83731989f5ce2c8c83073bbaed6fa7e3 Mon Sep 17 00:00:00 2001 From: Jo Date: Tue, 7 Jul 2026 13:33:28 +0200 Subject: [PATCH] fix: WAL mode on SQLite + longer timeout to prevent database locked errors --- app.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index ed6e20a..5ff68de 100644 --- a/app.py +++ b/app.py @@ -75,8 +75,10 @@ def require_login_global(): return redirect(url_for('login')) def get_db(): - conn = sqlite3.connect(DATABASE, timeout=10) + conn = sqlite3.connect(DATABASE, timeout=30) conn.row_factory = sqlite3.Row + conn.execute('PRAGMA journal_mode=WAL') + conn.execute('PRAGMA synchronous=NORMAL') return conn def init_db(): @@ -2038,8 +2040,10 @@ def _ha_sync_once(): states = _ha_fetch_all_states(ha_url, ha_token) if not states: return - conn = sqlite3.connect(DATABASE, timeout=15) + # Ouvrir la connexion d'écriture APRÈS l'appel HTTP (qui peut être long) + conn = sqlite3.connect(DATABASE, timeout=30) conn.row_factory = sqlite3.Row + conn.execute('PRAGMA journal_mode=WAL') printers = conn.execute( "SELECT id, name, ha_entity_prefix FROM printers " "WHERE ha_entity_prefix IS NOT NULL AND ha_entity_prefix != ''"