From 0de14c4c8bc4b64df53fd5d174fd932523f05c34 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 23 Sep 2024 11:07:52 -0400 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=85=8D=E7=BD=AE=E9=A1=B9=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/helper.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dashboard/helper.py b/dashboard/helper.py index 250b838ee..2cb744bad 100644 --- a/dashboard/helper.py +++ b/dashboard/helper.py @@ -23,6 +23,20 @@ class DashBoardHelper(): return float(value) elif type_ == "float" and isinstance(value, int): return float(value) + + def get_default_val_by_type(self, type_: str): + if type_ == "int": + return 0 + elif type_ == "float": + return 0.0 + elif type_ == "bool": + return False + elif type_ == "string": + return "" + elif type_ == "list": + return [] + elif type_ == "object": + return {} def validate_config(self, data): @@ -32,6 +46,10 @@ class DashBoardHelper(): if key not in data: continue value = data[key] + # null 转换 + if value is None: + data[key] = self.get_default_val_by_type(meta["type"]) + continue # 递归验证 if meta["type"] == "list" and isinstance(value, list): for item in value: