#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 |
Description
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 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 4 years ago
Has patch: | set |
---|
comment:3 by , 4 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 4 years ago
Patch needs improvement: | set |
---|
comment:5 by , 4 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:6 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:7 by , 4 years ago
Recently filed a related ticket to allow this or similar behavior to be default: #32590
In 3828879e: