Fix transaction isolation in AdvancedSQLiteSession.add_items#3455
Open
Doondi-Ashlesh wants to merge 1 commit into
Open
Fix transaction isolation in AdvancedSQLiteSession.add_items#3455Doondi-Ashlesh wants to merge 1 commit into
Doondi-Ashlesh wants to merge 1 commit into
Conversation
The method was committing message rows before writing structure metadata. If the metadata write failed, the rollback had no effect since the messages were already committed, leaving orphaned rows that get_items could not read. Both writes now share a single transaction with an explicit rollback on failure so callers get a clean exception and no partial state is left behind. Added a regression test that patches the metadata write to fail and checks that no orphaned rows remain and that a subsequent successful call works.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AdvancedSQLiteSession.add_itemscommitted message rows to the database before writing structure metadata. If the metadata write failed, the subsequent rollback had no effect because the message insert was already committed. This left orphaned rows in the messages table thatget_itemscould never return (it joins throughmessage_structure), so callers had no way to tell whether the operation actually succeeded.Both writes now share a single transaction. If anything fails, an explicit rollback removes the message rows too and the exception propagates to the caller so they can handle or retry it cleanly.
Test plan
Added
test_add_items_is_atomic_on_structure_metadata_failurewhich:_insert_structure_metadatato raise aRuntimeErroradd_itemsraises instead of silently succeedingadd_itemscall works normallyAll 37 existing tests in
test_advanced_sqlite_session.pycontinue to pass. No regressions in the wider test suite.Issue number
Closes #3348
Checks
make lintandmake format