Missing Transaction For Multi Write (ARCH2065)
Key python.orm.missing-transaction-for-multi-write · Severity warning · Category orm
Two or more dependent writes in the same method that are not wrapped in an explicit transaction/atomic block risk partial commits. Make the writes atomic.
Incorrect
Section titled “Incorrect”def transfer(src, dst, amount): src.balance -= amount src.save() # a failure after this loses the money dst.balance += amount dst.save()Correct
Section titled “Correct”def transfer(src, dst, amount): with transaction.atomic(): src.balance -= amount src.save() dst.balance += amount dst.save()Wrap dependent multi-write operations in transaction.atomic() so they commit all-or-nothing.