Repository navigation
Description
The first write in the quickstart raises. db.command("sql", "INSERT INTO Person SET name = 'Dora'") outside with db.transaction(): fails with Transaction not begun on both packages, and the quickstart shows that error as its second example. I want a first write to work with no ceremony, so I propose that a statement outside a transaction commits on its own by default, and that db.set_auto_transaction(False) brings today's strict behavior back.
What other libraries do: I ran or read the transaction behavior of 23 Python database libraries. 15 commit a statement outside a transaction at once (apsw, DuckDB, LadybugDB, LanceDB, ChromaDB, SurrealDB, pyoxigraph, rocksdict, asyncpg, the neo4j driver, FalkorDB, redis-py, pymongo, Qdrant, Weaviate). 7 open a transaction on the first statement and need an explicit commit (sqlite3 in its legacy mode, psycopg 3, SQLAlchemy, python-oracledb, mysql-connector, PyMySQL, pyodbc). One, LMDB, has no write call outside a transaction. None raises an error on a bare write. The 7 that need a commit do not keep an uncommitted write when the connection closes, and say nothing about it.
What I checked on both builds, with the main wheels of 24 November 2026 and the engine flag set to the proposed default:
begin()andwith db.transaction():are not committed for you, nested blocks keep their rules, andrun_in_transactionis unchanged.- A failed statement, also a multi-row
INSERTthat fails on its last row, leaves nothing behind. A query opens no transaction, and a write sent throughquery()is still refused. - A SQLScript without
BEGINcommits each statement alone, withBEGINandCOMMITit is all or nothing. save(),delete(),insert_manyandgraph_batchwork outside a transaction.insert_many(50,000 documents) andgraph_batch(20,000 vertices, 40,000 edges) run at the same speed with the flag on or off: 11 interleaved pairs for each load on each build give a median ratio on over off between 0.97 and 1.01, and an off against off control gives 0.984 to 1.041.- A thread without a transaction commits alone while another thread has one open, and the other thread's rollback does not take the row back.
- HTTP clients of the embedded server are not affected: a command without
beginalready works with the flag off. commit()with no transaction open still raisesTransaction not begun.
The real cost is a loop of single writes, because each one is a commit. This is the same cost as a loop that wraps every statement in its own with db.transaction():. Laptop, hot, noisy, not a claim, 5 repeats, median, one INSERT per row:
| Package | WAL flush | One transaction, rows/s | Bare writes, rows/s |
|---|---|---|---|
arcadedb-jvm |
default | 122,000 | 46,000 |
arcadedb |
default | 105,000 | 23,200 |
arcadedb-jvm |
yes_nometadata |
110,000 | 194 |
arcadedb |
yes_nometadata |
60,700 | 183 |
With a flush level that waits for the disk, one commit took about 5 milliseconds here. The transactions page will say this with the numbers and point to with db.transaction():, insert_many and graph_batch.
Options I looked at:
- (a) Flip the default in the Python layer, strict mode stays one call away. No program that works today breaks, because every bare write raised before. The ones that break are tests and code that assert the error. Migration:
db.set_auto_transaction(False)once after opening. - (b) A keyword on
open_databaseandcreate_databasethat defaults to strict now and flips in a later release. No break now and a deprecation to explain, but the first five minutes stay as they are for one more release. - (c) Keep the default and add a hint to the error ("wrap the write in
with db.transaction():or calldb.set_auto_transaction(True)"). No break, and a model can repair it, but a first write still fails. - (d) A separate
db.execute()that commits. No break, one more call to learn, anddb.commandkeeps failing.
I recommend (a), and I would add the hint of (c) to the strict mode message in a follow-up. The risks that remain are code that used the error to catch a forgotten transaction (it now commits statement by statement), the loop cost above, and on the native build a bare save() of an existing record, whose stale-record check and write are two statements outside a transaction. All three go into the transactions page.
The pull request for (a) is #479. I would put it in 26.12.1 only if both builds are green in CI; otherwise it goes to 27.1.1.
Activity
A write outside a transaction commits on its own: auto-transaction is…
Test: two writers with a bare save(), the stale one is refused with a…