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: use select for API key auth lookups (#34146)

Maa-Lee | odeilic5eae67ac92e
diff --git a/api/services/auth/api_key_auth_service.py b/api/services/auth/api_key_auth_service.py
index 56aaf407eeb..3282dcfb113 100644
--- a/api/services/auth/api_key_auth_service.py
+++ b/api/services/auth/api_key_auth_service.py
@@ -35,15 +35,13 @@ class ApiKeyAuthService:
@staticmethod
def get_auth_credentials(tenant_id: str, category: str, provider: str):
- data_source_api_key_bindings = (
- db.session.query(DataSourceApiKeyAuthBinding)
- .where(
+ data_source_api_key_bindings = db.session.scalar(
+ select(DataSourceApiKeyAuthBinding).where(
DataSourceApiKeyAuthBinding.tenant_id == tenant_id,
DataSourceApiKeyAuthBinding.category == category,
DataSourceApiKeyAuthBinding.provider == provider,
DataSourceApiKeyAuthBinding.disabled.is_(False),
)
- .first()
)
if not data_source_api_key_bindings:
return None
@@ -54,10 +52,11 @@ class ApiKeyAuthService:
@staticmethod
def delete_provider_auth(tenant_id: str, binding_id: str):
- data_source_api_key_binding = (
- db.session.query(DataSourceApiKeyAuthBinding)
- .where(DataSourceApiKeyAuthBinding.tenant_id == tenant_id, DataSourceApiKeyAuthBinding.id == binding_id)
- .first()
+ data_source_api_key_binding = db.session.scalar(
+ select(DataSourceApiKeyAuthBinding).where(
+ DataSourceApiKeyAuthBinding.tenant_id == tenant_id,
+ DataSourceApiKeyAuthBinding.id == binding_id,
+ )
)
if data_source_api_key_binding:
db.session.delete(data_source_api_key_binding)