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
This commit is contained in:
Claude 2026-07-04 18:46:09 +00:00
commit ffec11cfb7
No known key found for this signature in database
4 changed files with 59 additions and 1 deletions

View file

@ -2702,6 +2702,8 @@ You can disable WAL mode using ``.disable_wal()``:
Database("my_database.db").disable_wal()
The journal mode can only be changed outside of a transaction. Calling either method while a transaction is open - inside a ``db.atomic()`` block, for example - raises a ``RuntimeError``, unless the database is already in the requested mode in which case the call is a no-op.
You can check the current journal mode for a database using the ``journal_mode`` property:
.. code-block:: python