fix(#1137): add transaction context manager for atomic multi-write operations#1173
Closed
ionfwsrijan wants to merge 2 commits into
Closed
fix(#1137): add transaction context manager for atomic multi-write operations#1173ionfwsrijan wants to merge 2 commits into
ionfwsrijan wants to merge 2 commits into
Conversation
…ite operations - Add Database.transaction() async context manager (begin/commit/rollback) - Wrap _upsert_findings_and_report in transaction (findings + report + resources) - Wrap _upsert_findings_and_report_from_scanner in transaction - Wrap cancel_task status update + audit log in transaction - Wrap replace_asset_services delete+insert in transaction - Wrap delete_task_records in transaction (replacing manual begin/commit/rollback) - Wrap upsert_vault_secret select-then-upsert in transaction - Keep existing execute() auto-commit behavior for backward compatibility
- Fix indentation in replace_asset_services for loop body after wrapping in async with db.transaction() - Run ruff format on all 4 changed files
Contributor
Author
|
@utksh1 Please review this |
Owner
|
Closing this because it now conflicts with main after recent merges. Please rebase/update the branch and open a fresh PR if the change is still needed. |
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.
Problem
Every database write was auto-committed immediately (
execute()callsconnection.commit()after every query). Multi-write operations (findings insert +report insert, asset services delete+insert, task delete cascade) had no atomicity —
a crash midway would leave partial data.
Solution
Database.transaction()async context manager that wrapsBEGIN/COMMIT/ROLLBACK_upsert_findings_and_report(findings + report + result resources)_upsert_findings_and_report_from_scanner(same)cancel_task(status update + audit log)replace_asset_services(DELETE + INSERT loop)delete_task_records(replaced manualbegin()/commit()/rollback())upsert_vault_secret(SELECT-then-UPDATE/INSERT race)execute()retains its auto-commit default; callers that needatomicity opt in via
async with db.transaction():Files changed
backend/secuscan/database.py,backend/secuscan/executor.py,backend/secuscan/platform_resources.py,backend/secuscan/routes.pyCloses #1137