mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-01-20 17:44:26 +00:00
fix: Handle IntegrityError when bulk creating accounts from templates (#16554)
Co-authored-by: wangruidong <940853815@qq.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from django.db import IntegrityError
|
||||
from django.db.models import Q, Count
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
@@ -127,7 +128,11 @@ class AssetPermissionSerializer(ResourceLabelsMixin, BulkOrgResourceModelSeriali
|
||||
account_objs.append(Account(asset=asset, **account_data))
|
||||
|
||||
if account_objs:
|
||||
Account.objects.bulk_create(account_objs)
|
||||
try:
|
||||
Account.objects.bulk_create(account_objs)
|
||||
except IntegrityError as e:
|
||||
raise serializers.ValidationError(
|
||||
_('Please ensure that the selected account templates use the same username.'))
|
||||
|
||||
def create_account_through_template(self, nodes, assets):
|
||||
if not self.template_accounts:
|
||||
|
||||
Reference in New Issue
Block a user