forked from uncloud/uncloud
Wrap VM creation in database transaction
This commit is contained in:
parent
81bd54116a
commit
9e253d497b
1 changed files with 4 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
from django.db import transaction
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -27,10 +28,10 @@ class VMProductViewSet(ProductViewSet):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return VMProduct.objects.filter(owner=self.request.user)
|
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):
|
def create(self, request):
|
||||||
# TODO: what if something blows-up midway?
|
|
||||||
# => need a transaction
|
|
||||||
|
|
||||||
# Create base order.
|
# Create base order.
|
||||||
order = Order.objects.create(
|
order = Order.objects.create(
|
||||||
recurring_period=RecurringPeriod.PER_MONTH,
|
recurring_period=RecurringPeriod.PER_MONTH,
|
||||||
|
|
Loading…
Reference in a new issue