Is it safe to replace this code:
def view(request):
reporter.stories_filed = F('stories_filed') + 1
with this:
@transaction.atomic
def view(request):
reporter.stories_filed += 1
and is this wrong:
@transaction.atomic
def view(request):
reporter.stories_filed = F('stories_filed') + 1
?
The answer depends on the transaction isolation level used (most often the answer is NO)
I found a very detailed explanation here:
https://en.wikipedia.org/wiki/Isolation_(database_systems)
A brief summary: There are several transaction isolation levels which affect how transactions function, which level is used by Django depends on your RDBMS, it's settings etc.
Only "Serializable" transaction isolation level will prevent race conditions (the purpose of F object). And it is not used by default in most RDBMS and Django.
And the purpose of transactions is mostly another thing: to ensure that either all or none statements inside a transaction are committed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With