From 640b51c606f1aed8336a70f2332f9bbb00da33bb Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Fri, 28 Sep 2018 17:44:20 +0200 Subject: [PATCH] Ensure that add files to a playbook succeeds completly or not at all. Change-Id: Icda65cc73326df44d1a34543ef03827118e9b2f2 --- ara/api/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ara/api/views.py b/ara/api/views.py index b32d3d2..51cc790 100644 --- a/ara/api/views.py +++ b/ara/api/views.py @@ -14,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with ARA. If not, see . +from django.db import transaction from rest_framework import viewsets from rest_framework_extensions.mixins import NestedViewSetMixin @@ -36,8 +37,9 @@ class PlaybookFilesDetail(NestedViewSetMixin, viewsets.ModelViewSet): def perform_create(self, serializer): playbook = models.Playbook.objects.get(pk=self.get_parents_query_dict()['playbooks']) - instance = serializer.save() - playbook.files.add(instance) + with transaction.atomic(savepoint=False): + instance = serializer.save() + playbook.files.add(instance) class PlayViewSet(viewsets.ModelViewSet):