From b41d30dbacd3e654cc0b4dc255ac4dc974c7b211 Mon Sep 17 00:00:00 2001 From: Bai Date: Tue, 7 Feb 2023 15:56:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B5=84=E4=BA=A7=E6=97=B6=E5=8C=85=E5=90=AB?= =?UTF-8?q?labels=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98(=E5=8F=96?= =?UTF-8?q?=E6=B6=88id=E5=94=AF=E4=B8=80=E9=94=AE=E6=A0=A1=E9=AA=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/asset/asset.py | 3 ++- apps/assets/serializers/asset/common.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/assets/api/asset/asset.py b/apps/assets/api/asset/asset.py index 13f4b86ac..0e6bc0162 100644 --- a/apps/assets/api/asset/asset.py +++ b/apps/assets/api/asset/asset.py @@ -133,7 +133,8 @@ class AssetViewSet(SuggestionMixin, NodeFilterMixin, OrgBulkModelViewSet): def create(self, request, *args, **kwargs): if request.path.find('/api/v1/assets/assets/') > -1: - return Response({'error': _('Cannot create asset directly, you should create a host or other')}, status=400) + error = _('Cannot create asset directly, you should create a host or other') + return Response({'error': error}, status=400) return super().create(request, *args, **kwargs) diff --git a/apps/assets/serializers/asset/common.py b/apps/assets/serializers/asset/common.py index 4d6ea76c6..8057731bc 100644 --- a/apps/assets/serializers/asset/common.py +++ b/apps/assets/serializers/asset/common.py @@ -34,8 +34,10 @@ class AssetLabelSerializer(serializers.ModelSerializer): model = Label fields = ['id', 'name', 'value'] extra_kwargs = { + # 取消默认唯一键的校验 + 'id': {'validators': []}, 'name': {'required': False}, - 'value': {'required': False} + 'value': {'required': False}, }