@@ -187,7 +187,7 @@ Django provides a single API to control database transactions.
187
187
If you catch exceptions raised by raw SQL queries, Django's behavior
188
188
is unspecified and database-dependent.
189
189
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.
191
191
192
192
The values of a model's fields won't be reverted when a transaction
193
193
rollback happens. This could lead to an inconsistent model state unless
@@ -210,6 +210,14 @@ Django provides a single API to control database transactions.
210
210
if obj.active:
211
211
...
212
212
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
+
213
221
In order to guarantee atomicity, ``atomic`` disables some APIs. Attempting
214
222
to commit, roll back, or change the autocommit state of the database
215
223
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
290
298
where you want to run your own transaction-controlling middleware or do
291
299
something really strange.
292
300
301
+ .. _performing-actions-after-commit:
302
+
293
303
Performing actions after commit
294
304
===============================
295
305
0 commit comments