From b2f5ca356a90985f35ae538e608064e2c7afc957 Mon Sep 17 00:00:00 2001 From: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Date: Fri, 11 Apr 2025 15:20:03 +0800 Subject: [PATCH] enhance(plugin): replace json.loads with Pydantic model_validate_json (#17867) --- api/core/plugin/manager/base.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/api/core/plugin/manager/base.py b/api/core/plugin/manager/base.py index 7985aa68da..ea6b338725 100644 --- a/api/core/plugin/manager/base.py +++ b/api/core/plugin/manager/base.py @@ -168,15 +168,14 @@ class BasePluginManager: Make a stream request to the plugin daemon inner API and yield the response as a model. """ for line in self._stream_request(method, path, params, headers, data, files): - line_data = None try: - line_data = json.loads(line) - rep = PluginDaemonBasicResponse[type](**line_data) # type: ignore + rep = PluginDaemonBasicResponse[type].model_validate_json(line) # type: ignore except Exception: # TODO modify this when line_data has code and message - if line_data and "error" in line_data: + try: + line_data = json.loads(line) raise ValueError(line_data["error"]) - else: + except Exception: raise ValueError(line) if rep.code != 0: