From 57bad6353ce6343a6a16e3e6976ab9f3b9738948 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 14 Sep 2024 13:13:11 +0800 Subject: [PATCH] fix bug --- app/db/plugindata_oper.py | 2 +- app/db/systemconfig_oper.py | 2 +- app/db/userconfig_oper.py | 2 +- app/utils/object.py | 15 +++++++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/db/plugindata_oper.py b/app/db/plugindata_oper.py index 579d3550..6f271b42 100644 --- a/app/db/plugindata_oper.py +++ b/app/db/plugindata_oper.py @@ -36,7 +36,7 @@ class PluginDataOper(DbOper): data = PluginData.get_plugin_data_by_key(self._db, plugin_id, key) if not data: return None - if ObjectUtils.is_obj(data.value): + if ObjectUtils.is_objstr(data.value): return json.loads(data.value) return data.value else: diff --git a/app/db/systemconfig_oper.py b/app/db/systemconfig_oper.py index 59a23bdc..a7665f2e 100644 --- a/app/db/systemconfig_oper.py +++ b/app/db/systemconfig_oper.py @@ -18,7 +18,7 @@ class SystemConfigOper(DbOper, metaclass=Singleton): """ super().__init__() for item in SystemConfig.list(self._db): - if ObjectUtils.is_obj(item.value): + if ObjectUtils.is_objstr(item.value): self.__SYSTEMCONF[item.key] = json.loads(item.value) else: self.__SYSTEMCONF[item.key] = item.value diff --git a/app/db/userconfig_oper.py b/app/db/userconfig_oper.py index 04d066d5..520bad8e 100644 --- a/app/db/userconfig_oper.py +++ b/app/db/userconfig_oper.py @@ -18,7 +18,7 @@ class UserConfigOper(DbOper, metaclass=Singleton): """ super().__init__() for item in UserConfig.list(self._db): - value = json.loads(item.value) if ObjectUtils.is_obj(item.value) else item.value + value = json.loads(item.value) if ObjectUtils.is_objstr(item.value) else item.value self.__set_config_cache(username=item.username, key=item.key, value=value) def set(self, username: str, key: Union[str, UserConfigKey], value: Any): diff --git a/app/utils/object.py b/app/utils/object.py index c383a21f..edca9b1d 100644 --- a/app/utils/object.py +++ b/app/utils/object.py @@ -14,11 +14,18 @@ class ObjectUtils: elif isinstance(obj, int) \ or isinstance(obj, float) \ or isinstance(obj, bool) \ - or isinstance(obj, bytes): + or isinstance(obj, bytes) \ + or isinstance(obj, str): return False - else: - return str(obj).startswith("{") \ - or str(obj).startswith("[") + return True + + @staticmethod + def is_objstr(obj: Any): + if not isinstance(obj, str): + return False + return str(obj).startswith("{") \ + or str(obj).startswith("[") \ + or str(obj).startswith("(") @staticmethod def arguments(func: Callable) -> int: