Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 696fbc3

Browse filesBrowse files
lufafajoshuanessita
authored andcommitted
[4.2.x] Fixed #30601 -- Doc'd the need to manually revert all app state on transaction rollbacks.
Backport of aa80b35 from main
1 parent ffba631 commit 696fbc3
Copy full SHA for 696fbc3

File tree

Expand file treeCollapse file tree

1 file changed

+11
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-1
lines changed

‎docs/topics/db/transactions.txt

Copy file name to clipboardExpand all lines: docs/topics/db/transactions.txt
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Django provides a single API to control database transactions.
187187
If you catch exceptions raised by raw SQL queries, Django's behavior
188188
is unspecified and database-dependent.
189189

190-
.. admonition:: You may need to manually revert model state when rolling back a transaction.
190+
.. admonition:: You may need to manually revert app state when rolling back a transaction.
191191

192192
The values of a model's fields won't be reverted when a transaction
193193
rollback happens. This could lead to an inconsistent model state unless
@@ -210,6 +210,14 @@ Django provides a single API to control database transactions.
210210
if obj.active:
211211
...
212212

213+
This also applies to any other mechanism that may hold app state, such
214+
as caching or global variables. For example, if the code proactively
215+
updates data in the cache after saving an object, it's recommended to
216+
use :ref:`transcation.on_commit <performing-actions-after-commit>`
217+
instead, to defer cache alterations until the transaction is actually
218+
committed.
219+
220+
213221
In order to guarantee atomicity, ``atomic`` disables some APIs. Attempting
214222
to commit, roll back, or change the autocommit state of the database
215223
connection within an ``atomic`` block will raise an exception.
@@ -290,6 +298,8 @@ by Django or by third-party libraries. Thus, this is best used in situations
290298
where you want to run your own transaction-controlling middleware or do
291299
something really strange.
292300

301+
.. _performing-actions-after-commit:
302+
293303
Performing actions after commit
294304
===============================
295305

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.