Stop running sqlite-utils plugins on Datasette connections

Wrapping a connection in sqlite_utils.Database() runs sqlite-utils
plugins' prepare_connection hooks against it by default. Datasette's
write API views and introspection helpers now pass execute_plugins=False
(matching what utils/internal_db.py already did), so third-party
sqlite-utils plugins no longer touch Datasette's connections.

Also apply PRAGMA recursive_triggers=on in Datasette._prepare_connection
so every connection gets consistent trigger semantics - previously only
the write connection got it, as a side effect of the first sqlite-utils
based write.

Refs #2831

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N76afGMhBRQk528VF1LTpR
This commit is contained in:
Claude 2026-07-09 06:03:42 +00:00
commit 5cec9c9faa
No known key found for this signature in database
8 changed files with 75 additions and 8 deletions

View file

@ -1302,3 +1302,24 @@ async def test_database_close_is_idempotent(tmpdir):
# Second call should be a no-op, not raise
db.close()
ds._internal_database.close()
@pytest.mark.asyncio
async def test_recursive_triggers_enabled_on_all_connections(tmp_path):
# https://github.com/simonw/datasette/issues/2831
# Previously recursive_triggers was only enabled on the write connection,
# and only as a side effect of the first sqlite-utils based write - so
# trigger semantics could differ between connections
path = str(tmp_path / "test.db")
sqlite3.connect(path).close()
datasette = Datasette([path])
db = datasette.get_database("test")
write_value = await db.execute_write_fn(
lambda conn: conn.execute("PRAGMA recursive_triggers").fetchone()[0],
transaction=False,
)
read_value = await db.execute_fn(
lambda conn: conn.execute("PRAGMA recursive_triggers").fetchone()[0]
)
assert write_value == 1
assert read_value == 1