【发布时间】:2014-12-05 08:58:07
【问题描述】:
我有这样的代码:
@transaction.commit_on_success()
def foo():
# Performs various database operations and may raise exception
do_stuff()
my_object = MyModel.objects.create()
# Commit transaction so Celery task will see the newly created object
transaction.commit()
# Async call Celery task that does something with the new object
my_celery_task.delay(my_object.id)
这是否符合我的预期,即:
- 如果没有异常发生,
transaction.commit()执行提交 - 如果
do_stuff()引发异常,事务将回滚
我正在使用 Django 1.4 和 MySQL。
【问题讨论】:
标签: python mysql django celery