From d4493f0a538c4e7efbfdec6608c7f0440fd4b849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 5 Jan 2025 16:07:54 +0100 Subject: [PATCH] Ignore operational error when optimize SQLite database on connection The 'PRAGMA optimize' command can not run on a locked database which may happen when a nested transaction is started. Closes #13793 --- trytond/trytond/backend/sqlite/database.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trytond/trytond/backend/sqlite/database.py b/trytond/trytond/backend/sqlite/database.py index ed8dc264e7..dc4863cd55 100644 --- a/trytond/trytond/backend/sqlite/database.py +++ b/trytond/trytond/backend/sqlite/database.py @@ -525,7 +525,11 @@ class Database(DatabaseInterface): self._conn.execute('PRAGMA foreign_keys = ON') self._conn.execute('PRAGMA journal_mode = WAL') self._conn.execute('PRAGMA synchronous = NORMAL') - self._conn.execute('PRAGMA optimize') + try: + self._conn.execute('PRAGMA optimize') + except DatabaseOperationalError: + # database may be locked + pass return self def _make_uri(self):