Skip to content

fix(branching): keep a caller-owned transaction open when autocommit is off - #16

Open
konstde00 wants to merge 1 commit into
mitdbg:mainfrom
konstde00:fix/8-autocommit-caller-transaction
Open

konstde00 wants to merge 1 commit into
mitdbg:mainfrom
konstde00:fix/8-autocommit-caller-transaction

Conversation

@konstde00

Copy link
Copy Markdown
Contributor

Hi! Thanks for maintaining Chronos.

This covers the root writes BranchSession.execute, upsert_rows and delete_keys from #8. It doesn't change session.transaction(), so the issue's last point (nested transaction() following the same ownership rule) stays open.

Currently, with autocommit=False, those 3 methods commit a transaction that is already open on the connection when they are called outside session.transaction(). So the caller's earlier writes become durable and a later rollback() doesn't undo them. Now the entry commit runs only when the context owns autocommit, the same rule _commit_autocommit already applies after the write, and execute starts a transaction only if none is open. With the default autocommit=True nothing changes.

I left session.transaction() out because joining a caller transaction there is a design choice. Please let me know which behaviour you want, and I can do it here or in a follow-up.

The new test_autocommit_false_keeps_caller_transaction_open covers the 3 methods on SQLite and PostgreSQL 16, with 6 failures before the change and tests/test_reused_session_transactions.py giving 8 passed after. The rest of pytest tests fails the same tests on the base commit and here (they need ChronosFS, DuckDB, S3 or Qdrant).

Relates to #8.

Thank you!

…is off

BranchSession.execute, upsert_rows and delete_keys committed any open
transaction on entry, even for a context created with autocommit=False,
so earlier writes of the caller became durable and a later rollback by
the caller did not undo them. Commit on entry only when the context owns
autocommit, and begin a transaction only if none is open.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant