mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
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.
This commit is contained in:
@ -188,8 +188,22 @@ class SandboxProviderService:
|
|||||||
id=tenant_configed.id, provider_type=tenant_configed.provider_type, config=config
|
id=tenant_configed.id, provider_type=tenant_configed.provider_type, config=config
|
||||||
)
|
)
|
||||||
else:
|
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()
|
system_configed: SandboxProviderSystemConfig | None = session.query(SandboxProviderSystemConfig).first()
|
||||||
if system_configed:
|
if system_configed:
|
||||||
return SandboxProviderEntity(
|
return SandboxProviderEntity(
|
||||||
@ -201,8 +215,10 @@ class SandboxProviderService:
|
|||||||
raise ValueError(f"No sandbox provider configured for tenant {tenant_id}")
|
raise ValueError(f"No sandbox provider configured for tenant {tenant_id}")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_system_default_config(cls, session: Session, tenant_id: str) -> SandboxProviderEntity:
|
def get_system_default_config(cls, session: Session, tenant_id: str, provider_type: str) -> SandboxProviderEntity:
|
||||||
system_configed: SandboxProviderSystemConfig | None = session.query(SandboxProviderSystemConfig).first()
|
system_configed: SandboxProviderSystemConfig | None = (
|
||||||
|
session.query(SandboxProviderSystemConfig).filter_by(provider_type=provider_type).first()
|
||||||
|
)
|
||||||
if system_configed:
|
if system_configed:
|
||||||
return SandboxProviderEntity(
|
return SandboxProviderEntity(
|
||||||
id=system_configed.id,
|
id=system_configed.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user