Skip to content

fix: roll back failed transaction commits - #316

Merged
chrispader merged 2 commits into
margelo:mainfrom
huytdps13400:fix/307-rollback-failed-commit
Oct 1, 2026
Merged

chrispader merged 2 commits into
margelo:mainfrom
huytdps13400:fix/307-rollback-failed-commit

Conversation

@huytdps13400

@huytdps13400 huytdps13400 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

A failed COMMIT currently marks the transaction finished before SQLite accepts it, so the wrapper skips rollback and leaves the connection inside the failed transaction. This PR tracks finalization states and attempts rollback after automatic or manual commit failures. A callback that catches a failed manual commit also rejects and rolls back unless it explicitly recovers with rollback.

The wrapper retains the current connection queue and waits for pending async statements before cleanup. If rollback also fails, the error preserves the primary message and exposes both normalized failures through an AggregateError cause. Caught manual rollback failures reject the transaction promise, and failed BEGIN does not roll back a transaction the wrapper did not start.

Reproduction

Enable foreign keys and insert a missing parent reference into a table with a deferred foreign-key constraint inside transaction(). Automatic commit, manual commit, and a caught manual commit must reject with the foreign-key error, discard the invalid row, and allow a second transaction on the same connection. The example regressions cover these flows; the local wrapper suite also exercises them against real SQLite.

Fixes #307.

Track transaction finalization states explicitly and preserve commit failures while rolling back deferred constraint errors. Closes margelo#307.
@chrispader chrispader added bug Incorrect behavior or a change that fixes it. area:runtime Database lifecycle, SQL execution, transactions, or native runtime. labels Sep 29, 2026
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

@chrispader is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

@chrispader

Copy link
Copy Markdown
Member

Thanks for the PR @huytdps13400 🙌🏼

@chrispader
chrispader merged commit 46b6e7d into margelo:main Oct 1, 2026
4 of 8 checks passed
@vercel

vercel Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
react-native-nitro-sqlite Ready Ready Preview Oct 1, 2026 10:14am UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 6bc66211 Deployed Oct 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Database lifecycle, SQL execution, transactions, or native runtime. bug Incorrect behavior or a change that fixes it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed COMMIT leaves transaction open and breaks subsequent transactions

2 participants