The Nested Django transaction - "with transaction.atomic ()" asked the question, given that ...
def functionA():
with transaction.atomic():
functionB()
def functionB():
with transaction.atomic():
If functionBit fails and rolls back, then functionArolls back too?
Kevin Christopher Henry replies: "Yes, if an exception occurs in any of the functions, they will both be rolled back." He then cites documents that state:
atomic blocks can be nested. In this case, when the indoor unit is successfully completed, its effects can still be discarded if an exception is added to the outdoor unit at a later point.
. , INNER BLOCK ( functionB) , , OUTER ( A) . . , INNER (functionB) FAILS, OUTER (functionA) ? .
...
from django.db import IntegrityError, transaction
@transaction.atomic
def viewfunc(request):
create_parent()
try:
with transaction.atomic():
generate_relationships()
except IntegrityError:
handle_exception()
add_children()
... ...
, generate_relationships() , , add_children(), create_parent() .
, , generate_relationships() ( functionB ) FAIL, , create_parent() add_children(), . , , .
, , / Django, Transaction.atomic.
Django stackoverflow, , , , . - - . .