Django嵌套事务 – “with transaction.atomic()”

我想知道我是否有这样的事情:

def functionA():
    with transaction.atomic():
        #save something
        functionB()

def functionB():
    with transaction.atomic():
        #save another thing

有人知道会发生什么?如果函数B失败,函数A也会回滚?

谢谢!

是的,反之亦然。从the docs

atomic blocks can be nested. In this case, when an inner block completes successfully, its effects can still be rolled back if an exception is raised in the outer block at a later point.

翻译自:https://stackoverflow.com/questions/22012071/django-nested-transactions-with-transaction-atomic

转载注明原文:Django嵌套事务 – “with transaction.atomic()”