Skip to content

Commit 1289eb0

Browse files
simonwclaude
andcommitted
Fix SQLite locking issue in execute_write_script
The execute_write_script() method was causing SQLite database locking errors when multiple executescript() calls ran in quick succession. Root cause: SQLite's executescript() method has special behavior - it implicitly commits any pending transaction and operates in autocommit mode. However, execute_write_script() was passing these calls through execute_write_fn() with the default transaction=True, which wrapped the executescript() call in a transaction context (with conn:). This created a conflict where sequential executescript() calls would cause the second call to fail with "OperationalError: database table is locked: sqlite_master" because the sqlite_master table was still locked from the first operation's implicit commit. Fix: Pass transaction=False to execute_write_fn() since executescript() manages its own transactions and should not be wrapped in an additional transaction context. This was causing test_hook_extra_body_script to fail because the internal database initialization (which calls executescript twice in succession) would fail, preventing the application from rendering pages correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5da3c9f commit 1289eb0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

datasette/database.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ def _inner(conn):
143143
return conn.executescript(sql)
144144

145145
with trace("sql", database=self.name, sql=sql.strip(), executescript=True):
146-
results = await self.execute_write_fn(_inner, block=block)
146+
results = await self.execute_write_fn(
147+
_inner, block=block, transaction=False
148+
)
147149
return results
148150

149151
async def execute_write_many(self, sql, params_seq, block=True):

0 commit comments

Comments
 (0)