From 4c24e95b4758839d5ec4ab5d9b501af510c57288 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 14 Mar 2023 14:12:42 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20csv=20parse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/asset/common.py | 2 +- apps/common/drf/parsers/base.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/assets/models/asset/common.py b/apps/assets/models/asset/common.py index 74df4a358..3a38699e8 100644 --- a/apps/assets/models/asset/common.py +++ b/apps/assets/models/asset/common.py @@ -108,7 +108,7 @@ class Asset(NodesRelationMixin, AbsConnectivity, JMSOrgBaseModel): verbose_name=_("Nodes")) is_active = models.BooleanField(default=True, verbose_name=_('Is active')) labels = models.ManyToManyField('assets.Label', blank=True, related_name='assets', verbose_name=_("Labels")) - info = models.JSONField(verbose_name='Info', default=dict, blank=True) # 资产的一些信息,如 硬件信息 + info = models.JSONField(verbose_name=_('Info'), default=dict, blank=True) # 资产的一些信息,如 硬件信息 objects = AssetManager.from_queryset(AssetQuerySet)() diff --git a/apps/common/drf/parsers/base.py b/apps/common/drf/parsers/base.py index 72bedcc97..7f3d4b055 100644 --- a/apps/common/drf/parsers/base.py +++ b/apps/common/drf/parsers/base.py @@ -91,7 +91,11 @@ class BaseFileParser(BaseParser): (col.startswith('[') and col.endswith(']')) or (col.startswith("{") and col.endswith("}")) ): - col = json.loads(col) + try: + col = json.loads(col) + except json.JSONDecodeError as e: + logger.error('Json load error: ', e) + logger.error('col: ', col) new_row.append(col) return new_row