Wrap multi-step DB operations in transactions to prevent partial writes #9
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Multi-step database operations that must succeed or fail atomically are executed as separate, unguarded DB calls. If the second call fails, the first write is committed and leaves orphaned or inconsistent data.
Key examples:
compliance/services/change_request_engine.py:36-52— creates a change request record, then updates the source document in separate transactionsRequired Actions
compliance/services/db.begin_nested()savepoint or ensure the SQLAlchemy session is committed atomically at the end of the request via a singledb.commit()try/except/rollbackin every service that mutates multiple tablesatomic(db)to enforce this pattern consistentlyAcceptance Criteria
db.commit()calls without explicit rollback handling