From 5f0a21d2d4d87c0eaa944e19c7802ab4cb7dcd23 Mon Sep 17 00:00:00 2001 From: Harry Date: Fri, 23 Jan 2026 02:06:00 +0800 Subject: [PATCH] refactor(sandbox): enhance system default configuration retrieval - Updated the `get_system_default_config` method to accept a `provider_type` parameter for more precise querying. - Improved error handling to raise a ValueError if no system default provider is configured for the specified tenant and provider type. - Added fallback logic to ensure a system default configuration is returned when available. --- .../sandbox/sandbox_provider_service.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/api/services/sandbox/sandbox_provider_service.py b/api/services/sandbox/sandbox_provider_service.py index a73570ff7b..83268c5f5a 100644 --- a/api/services/sandbox/sandbox_provider_service.py +++ b/api/services/sandbox/sandbox_provider_service.py @@ -188,8 +188,22 @@ class SandboxProviderService: id=tenant_configed.id, provider_type=tenant_configed.provider_type, config=config ) else: - return cls.get_system_default_config(session, tenant_id) + system_configed: SandboxProviderSystemConfig | None = ( + session.query(SandboxProviderSystemConfig) + .filter_by(provider_type=tenant_configed.provider_type) + .first() + ) + if not system_configed: + raise ValueError( + f"No system default provider configured for tenant {tenant_id} and provider type {tenant_configed.provider_type}" + ) + return SandboxProviderEntity( + id=tenant_configed.id, + provider_type=system_configed.provider_type, + config=decrypt_system_params(system_configed.encrypted_config), + ) + # fallback to system default config system_configed: SandboxProviderSystemConfig | None = session.query(SandboxProviderSystemConfig).first() if system_configed: return SandboxProviderEntity( @@ -201,8 +215,10 @@ class SandboxProviderService: raise ValueError(f"No sandbox provider configured for tenant {tenant_id}") @classmethod - def get_system_default_config(cls, session: Session, tenant_id: str) -> SandboxProviderEntity: - system_configed: SandboxProviderSystemConfig | None = session.query(SandboxProviderSystemConfig).first() + def get_system_default_config(cls, session: Session, tenant_id: str, provider_type: str) -> SandboxProviderEntity: + system_configed: SandboxProviderSystemConfig | None = ( + session.query(SandboxProviderSystemConfig).filter_by(provider_type=provider_type).first() + ) if system_configed: return SandboxProviderEntity( id=system_configed.id,