Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32220 closed New feature (fixed)

Add a 'durable' flag to transaction.atomic()

Reported by: Adam Johnson Owned by: Ian Foote
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


As discussed on Twitter following David Seddon's blog post.

transaction.atomic() guarantees the wrapped database operations is *atomic* - at the end of its wrapped block, operations within that block will all be applied, or all rolled back. In some situations it's also useful to guarantee that the wrapped operations are *durable* - at the end of the wrapped block, all operations have definitely been committed. atomic() doesn't guarantee this at the moment since its use may be wrapped by *another* atomic() higher in the stack, delaying the commit.

David Seddon's technique to guarantee durability is to wrap atomic() to first check if an atomic() is already active for the current connection (in other words, connection.get_autocommit() returns False), and raise an error if so.

On Twitter, Ian Foote suggested adding a durable flag to atomic() to add this behaviour to Django, to which Aymeric Augustin said it sounds like a good idea.

Change History (7)

comment:1 Changed 3 years ago by Ian Foote

Owner: changed from nobody to Ian Foote
Status: newassigned

comment:2 Changed 3 years ago by Ian Foote

Has patch: set

comment:3 Changed 3 years ago by Mariusz Felisiak

Triage Stage: UnreviewedAccepted

comment:4 Changed 3 years ago by Mariusz Felisiak

Patch needs improvement: set

comment:5 Changed 3 years ago by Mariusz Felisiak

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:6 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 3828879e:

Fixed #32220 -- Added durable argument to transaction.atomic().

comment:7 Changed 3 years ago by Alex Rattray

Recently filed a related ticket to allow this or similar behavior to be default: #32590

Last edited 3 years ago by Tim Graham (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top