Skip to content

Instantly share code, notes, and snippets.

@wanshot
Last active December 10, 2018 08:52
Show Gist options
  • Save wanshot/b29da948229694278168d35c8539cde7 to your computer and use it in GitHub Desktop.
Save wanshot/b29da948229694278168d35c8539cde7 to your computer and use it in GitHub Desktop.
Djangoのview内でのトランザクション
views.py
def hoge(request):
    with transaction.atomic():
        tasks.huga.delay()
    retrun response
  • 上記コードのトランザクションの範囲は、celeryのジョブキューにタスクを積むという処理に対してかかるので意味がない。
  • hoge関数の処理にトランザクションをかけたい場合は、タスクの処理内にトランザクションを記述する。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment