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
This commit is contained in:
Cédric Krier
2025-01-05 16:07:54 +01:00
parent b5148a248c
commit d4493f0a53
+5 -1
View File
@@ -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):