From dbaa4ab502e3411aa01eaf65f02028fa759f3e39 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 26 Mar 2018 15:55:31 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=9A=84=E4=BA=8B=E5=8A=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/views/asset.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/assets/views/asset.py b/apps/assets/views/asset.py index 900018670..c3fbd4758 100644 --- a/apps/assets/views/asset.py +++ b/apps/assets/views/asset.py @@ -9,6 +9,7 @@ import chardet from io import StringIO from django.conf import settings +from django.db import transaction from django.utils.translation import ugettext_lazy as _ from django.views.generic import TemplateView, ListView, View from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView @@ -294,9 +295,10 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView): try: if len(Asset.objects.filter(hostname=asset_dict.get('hostname'))): raise Exception(_('already exists')) - asset = Asset.objects.create(**asset_dict) - created.append(asset_dict['hostname']) - assets.append(asset) + with transaction.atomic(): + asset = Asset.objects.create(**asset_dict) + created.append(asset_dict['hostname']) + assets.append(asset) except Exception as e: failed.append('%s: %s' % (asset_dict['hostname'], str(e))) else: -- GitLab