`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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32220>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Ian Foote
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32220#comment:1>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/32220#comment:2>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/32220#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/32220#comment:4>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32220#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"3828879eee09da95bf99886c1ae182a36b1d89b3" 3828879e]:
{{{
#!CommitTicketReference repository=""
revision="3828879eee09da95bf99886c1ae182a36b1d89b3"
Fixed #32220 -- Added durable argument to transaction.atomic().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32220#comment:6>
Comment (by Alex Rattray):
Recently filed a related ticket to allow this or similar behavior to be
default: https://code.djangoproject.com/ticket/32590
--
Ticket URL: <https://code.djangoproject.com/ticket/32220#comment:7>