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.

http://stackoverflow.com/questions/22012071/django-nested-transactions-with-transaction-atomic

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:Django嵌套事务 – “with transaction.atomic()”