Skip to content

armgit / dify

Public Imported from GitHub
0

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.

refactor(api): read provider configuration cache rows via pydantic (#44055)

gongfpp7c6b8fa3f144
diff --git a/api/core/provider_manager.py b/api/core/provider_manager.py
index b62c7747bb4..1602a8055b1 100644
--- a/api/core/provider_manager.py
+++ b/api/core/provider_manager.py
@@ -69,6 +69,7 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__)
_credentials_adapter: TypeAdapter[dict[str, Any]] = TypeAdapter(dict[str, Any])
+_provider_configuration_cache_rows_adapter: TypeAdapter[list[Any]] = TypeAdapter(list[Any])
_PROVIDER_CONFIGURATION_CACHE_TTL_SECONDS = 300
_PROVIDER_CONFIGURATION_CACHE_VERSION_TTL_SECONDS = 360
_PROVIDER_CONFIGURATION_CACHE_VERSION_KEY = "provider_configurations:tenant:{tenant_id}:source:{source}:version"
@@ -356,9 +357,7 @@ class _ProviderConfigurationSourceCache:
return None, version
cached_text = cached_records.decode("utf-8") if isinstance(cached_records, bytes) else cached_records
- rows = json.loads(cached_text)
- if not isinstance(rows, list):
- return None, version
+ rows = _provider_configuration_cache_rows_adapter.validate_json(cached_text)
return [entry_cls.from_cache_row(row) for row in rows if isinstance(row, dict)], version
except Exception: