From 9e253d497bfcdb41dc54df94ad9d85c55b554492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Mon, 2 Mar 2020 09:30:51 +0100 Subject: [PATCH] Wrap VM creation in database transaction --- uncloud/uncloud_vm/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/uncloud/uncloud_vm/views.py b/uncloud/uncloud_vm/views.py index 5eeec7b..5de904c 100644 --- a/uncloud/uncloud_vm/views.py +++ b/uncloud/uncloud_vm/views.py @@ -1,3 +1,4 @@ +from django.db import transaction from django.shortcuts import render from django.contrib.auth.models import User @@ -27,10 +28,10 @@ class VMProductViewSet(ProductViewSet): def get_queryset(self): return VMProduct.objects.filter(owner=self.request.user) + # Use a database transaction so that we do not get half-created structure + # if something goes wrong. + @transaction.atomic def create(self, request): - # TODO: what if something blows-up midway? - # => need a transaction - # Create base order. order = Order.objects.create( recurring_period=RecurringPeriod.PER_MONTH,