Skip to content

A write outside a transaction should commit on its own by default, with strict mode as an opt-in #478

Done

Description

@tae898

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() and with db.transaction(): are not committed for you, nested blocks keep their rules, and run_in_transaction is unchanged.
  • A failed statement, also a multi-row INSERT that fails on its last row, leaves nothing behind. A query opens no transaction, and a write sent through query() is still refused.
  • A SQLScript without BEGIN commits each statement alone, with BEGIN and COMMIT it is all or nothing.
  • save(), delete(), insert_many and graph_batch work outside a transaction. insert_many (50,000 documents) and graph_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 begin already works with the flag off.
  • commit() with no transaction open still raises Transaction 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_database and create_database that 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 call db.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, and db.command keeps 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

  1. added this to the 27.1.1 milestone on Nov 24, 2026
  2. self-assigned this
    on Nov 24, 2026
  3. added
    enhancement
    concurrency
    native
    jvm
    on Nov 24, 2026
  4. added
    in progress
    github_actions
    performance
    python
    on Nov 24, 2026
  5. modified the milestones: 27.1.1, 26.12.1 on Nov 24, 2026
  6. added 2 commits that reference this issue on Nov 24, 2026
    ac01e44
    81bb9cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

concurrencyenhancementgithub_actionsin progressjvmnativeperformancepython

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions