Repository navigation
Conversation
When the filter callback of applyChangeset() throws, xFilter can only tell SQLite to skip the remaining tables, so sqlite3changeset_apply() returns SQLITE_OK and the tables accepted before the exception stay applied. An exception from onConflict, by contrast, aborts and rolls back the whole apply. Wrap the apply in a savepoint when a filter is given and roll back to it when the filter threw. A savepoint is used instead of a transaction so that a transaction the caller already has open, and the writes made in it before the call, are kept. Fixes: nodejs#67841 Signed-off-by: Ultranmus <hashmack007@gmail.com>
|
Review requested:
|
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. Caution AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context. |
When the
filtercallback ofdatabase.applyChangeset()throws, the call throws but the tables accepted before the exception stay applied. An exception fromonConflictrolls everything back, becausexConflictreturnsSQLITE_CHANGESET_ABORT.xFilterhas no way to abort: returningfalseonly skips the table, sosqlite3changeset_apply()finishes withSQLITE_OKfor the tables it already applied.This wraps the apply in a savepoint when a
filteris given, and rolls back to it when the filter threw. A savepoint is used rather than a transaction so that, when the caller already has a transaction open, the earlier writes in it are kept and the transaction stays usable (the case raised in #67841 (comment)). The cleanup follows the sameRELEASE/ROLLBACK TO+RELEASEsequence thatsqlite3changeset_apply()uses for its own savepoint. Calls without afilterare unchanged.Tests cover the issue's repro, the open-outer-transaction case, and a non-throwing filter inside a transaction (to check that releasing the savepoint does not commit the outer transaction). The docs now describe what happens when
filterthrows.The v22.x abort (
FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal) is a separate issue: #60028 was not backported there. This PR does not address it.Tested on macOS arm64 (release build of main + this commit):
make test-sqliteandtools/test.py "test/parallel/test-sqlite*"pass. The issue's repro, plus the outer-transaction case:a: 1, b: 0a: 0, b: 0a: 1, b: 0, marker: 1a: 0, b: 0, marker: 1, txn still openAI use: Used AI tool for comment writing, PR description and assistance in testing
Fixes: #67841