summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlufafajoshua <77637648+lufafajoshua@users.noreply.github.com>2023-10-27 15:05:31 +0300
committerNatalia <124304+nessita@users.noreply.github.com>2023-10-27 23:33:45 -0300
commit696fbc32d6185283859b3a84277f49937a3012fc (patch)
treedfa49dcc74036602bac5e537156d465be4cb7d04
parentffba63180c86a73527b7af4b31564c62788d60cd (diff)
[4.2.x] Fixed #30601 -- Doc'd the need to manually revert all app state on transaction rollbacks.
Backport of aa80b357fbef46e5b6faa08d63bcfd4fe21f3776 from main
-rw-r--r--docs/topics/db/transactions.txt12
1 files changed, 11 insertions, 1 deletions
diff --git a/docs/topics/db/transactions.txt b/docs/topics/db/transactions.txt
index 2eba10496b..b3388c141f 100644
--- a/docs/topics/db/transactions.txt
+++ b/docs/topics/db/transactions.txt
@@ -187,7 +187,7 @@ Django provides a single API to control database transactions.
If you catch exceptions raised by raw SQL queries, Django's behavior
is unspecified and database-dependent.
- .. admonition:: You may need to manually revert model state when rolling back a transaction.
+ .. admonition:: You may need to manually revert app state when rolling back a transaction.
The values of a model's fields won't be reverted when a transaction
rollback happens. This could lead to an inconsistent model state unless
@@ -210,6 +210,14 @@ Django provides a single API to control database transactions.
if obj.active:
...
+ This also applies to any other mechanism that may hold app state, such
+ as caching or global variables. For example, if the code proactively
+ updates data in the cache after saving an object, it's recommended to
+ use :ref:`transcation.on_commit <performing-actions-after-commit>`
+ instead, to defer cache alterations until the transaction is actually
+ committed.
+
+
In order to guarantee atomicity, ``atomic`` disables some APIs. Attempting
to commit, roll back, or change the autocommit state of the database
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
where you want to run your own transaction-controlling middleware or do
something really strange.
+.. _performing-actions-after-commit:
+
Performing actions after commit
===============================