From e978209ebcef6a4f0736e7dd1701933c71200844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Mon, 8 Aug 2016 00:13:53 +0200 Subject: [PATCH] =?UTF-8?q?Enregistrement=20des=20op=C3=A9rations=20dans?= =?UTF-8?q?=20K-Psul?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ajout d'une transaction pour tous les save lors d'une commande K-Psul afin de préserver la cohérence de la BDD --- kfet/views.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index b9384231..5c927fc3 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -450,14 +450,18 @@ def kpsul_perform_operations(request): # Filling cof status for statistics operationgroup.is_cof = operationgroup.on_acc.is_cof - # Saving operation group - operationgroup.save() - data['operationgroup'] = operationgroup.pk - # Filling operationgroup id for each operations and saving - for operation in operations: - operation.group = operationgroup - operation.save() - data['operations'].append(operation.pk) + # Apply all saves in a transaction to ensure database integrity + try: + with transaction.atomic: + # Saving operation group + operationgroup.save() + data['operationgroup'] = operationgroup.pk + + # Filling operationgroup id for each operations and saving + for operation in operations: + operation.group = operationgroup + operation.save() + data['operations'].append(operation.pk) return JsonResponse(data)