Commit graph

5 commits

Author SHA1 Message Date
Simon Willison
6df6da1a8e Rename ensure_autocommit_off() to ensure_autocommit_on(), closes #705
The ensure_autocommit_off() context manager was misleadingly named: it
sets isolation_level = None on the underlying sqlite3 connection, which
puts the driver INTO autocommit mode (no implicit transactions) - the
opposite of what the name and docstring claimed.

The behavior was always correct for its call sites, which need
autocommit to run PRAGMA statements like journal_mode=wal. This renames
the method to ensure_autocommit_on() with an accurate docstring, updates
the three internal call sites, adds tests, and documents the rename in
the changelog and the 3.x to 4.0 upgrading guide. The old name is
removed outright since 4.0 permits breaking changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-05 21:50:20 -07:00
Claude
96793668ed
Raise TransactionError instead of RuntimeError from enable_wal/disable_wal
A dedicated sqlite_utils.db.TransactionError exception is clearer
to catch than a generic RuntimeError, and gives future
transaction-state guards a home.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnLnhsH25Nnv7LHhekUfPd
2026-07-04 22:32:36 +00:00
Claude
ffec11cfb7
enable_wal() and disable_wal() refuse to run inside a transaction
Changing the journal mode assigns conn.isolation_level, which
commits any open transaction as a side effect - silently breaking
the rollback guarantee of atomic() blocks and of user-managed
transactions. Both methods now raise RuntimeError if a transaction
is open. Calling them when the database is already in the requested
mode remains a no-op.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnLnhsH25Nnv7LHhekUfPd
2026-07-04 18:46:09 +00:00
Simon Willison
90e211e3e2 Now complies with flake8, refs #291 2021-06-22 18:22:08 -07:00
Simon Willison
c449064297 Additional tests for WAL mode
This should have been included in 2d2d724e32

Refs #132
2020-09-07 13:46:12 -07:00