Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix: accept legacy plugin daemon list responses (#38265)
蓝破碎半圆/破碎蓝调ba5e7d76fd81
diff --git a/api/core/plugin/impl/base.py b/api/core/plugin/impl/base.pyindex ce40c53c715..385ab67e34f 100644--- a/api/core/plugin/impl/base.py+++ b/api/core/plugin/impl/base.py@@ -12,7 +12,12 @@ from yarl import URLfrom configs import dify_configfrom core.helper.http_client_pooling import get_pooled_http_clientfrom core.plugin.endpoint.exc import EndpointSetupFailedError-from core.plugin.entities.plugin_daemon import PluginDaemonBasicResponse, PluginDaemonError, PluginDaemonInnerError+from core.plugin.entities.plugin_daemon import (+ PluginDaemonBasicResponse,+ PluginDaemonError,+ PluginDaemonInnerError,+ PluginListResponse,+)from core.plugin.impl.exc import (PluginDaemonBadRequestError,PluginDaemonClientSideError,@@ -66,6 +71,28 @@ _httpx_client: httpx.Client = get_pooled_http_client()+def _normalize_plugin_daemon_response_for_type(json_response: Any, type_: type[object]) -> Any:+ if type_ is not PluginListResponse:+ return json_response++ if isinstance(json_response, list):+ return {+ "code": 0,+ "message": "",+ "data": {"list": json_response, "total": len(json_response)},+ }++ if isinstance(json_response, dict):+ data = json_response.get("data")+ if isinstance(data, list):+ return {+ **json_response,+ "data": {"list": data, "total": len(data)},+ }++ return json_response++class BasePluginClient:def _request(self,@@ -274,6 +301,7 @@ class BasePluginClient:json_response = response.json()if transformer:json_response = transformer(json_response)+ json_response = _normalize_plugin_daemon_response_for_type(json_response, type_)# https://stackoverflow.com/questions/59634937/variable-foo-class-is-not-valid-as-type-but-whyrep = PluginDaemonBasicResponse[type_].model_validate(json_response) # type: ignoreexcept Exception as e:diff --git a/api/tests/unit_tests/core/plugin/impl/test_base_client_impl.py b/api/tests/unit_tests/core/plugin/impl/test_base_client_impl.pyindex 25b9ec4ef28..3eff5112ec3 100644--- a/api/tests/unit_tests/core/plugin/impl/test_base_client_impl.py+++ b/api/tests/unit_tests/core/plugin/impl/test_base_client_impl.py@@ -5,7 +5,7 @@ import pytestfrom pytest_mock import MockerFixturefrom core.plugin.endpoint.exc import EndpointSetupFailedError-from core.plugin.entities.plugin_daemon import PluginDaemonInnerError+from core.plugin.entities.plugin_daemon import PluginDaemonInnerError, PluginListResponsefrom core.plugin.impl.base import PLUGIN_DAEMON_MAX_PATH_LENGTH, BasePluginClientfrom core.plugin.impl.exc import PluginLLMPollingUnsupportedError, PluginRuntimeErrorfrom core.trigger.errors import (@@ -121,6 +121,26 @@ class TestBasePluginClientImpl:assert result is Trueassert transformed == {"code": 0, "message": "", "data": True}+ def test_request_with_plugin_daemon_response_accepts_legacy_plugin_list_data_array(self, mocker: MockerFixture):+ client = BasePluginClient()+ mocker.patch.object(client, "_request", return_value=_ResponseStub({"code": 0, "message": "", "data": []}))++ result = client._request_with_plugin_daemon_response("GET", "plugin/tenant/management/list", PluginListResponse)++ assert result.list == []+ assert result.total == 0++ def test_request_with_plugin_daemon_response_accepts_legacy_plugin_list_top_level_array(+ self, mocker: MockerFixture+ ):+ client = BasePluginClient()+ mocker.patch.object(client, "_request", return_value=_ResponseStub([]))++ result = client._request_with_plugin_daemon_response("GET", "plugin/tenant/management/list", PluginListResponse)++ assert result.list == []+ assert result.total == 0+def test_request_with_plugin_daemon_response_stream_malformed_json_error(self, mocker: MockerFixture):client = BasePluginClient()mocker.patch.object(client, "_stream_request", return_value=iter(['{"error":"bad-line"}']))