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.

chore(api): remove redundant str() on StringUUID ids (#43061)

Denis Ermakov18fea7ff0ddb
diff --git a/api/controllers/common/rbac/locators.py b/api/controllers/common/rbac/locators.py
index 3cc5d5373e6..16790059045 100644
--- a/api/controllers/common/rbac/locators.py
+++ b/api/controllers/common/rbac/locators.py
@@ -116,7 +116,7 @@ class AgentBehindApp(_ParamLocator):
binding = agent_binding(tenant_id, _required(path_args, self.param))
if binding is None or binding.scope == AgentScope.WORKFLOW_ONLY:
return None
- return ResourceIdentity(self.scope, str(binding.id))
+ return ResourceIdentity(self.scope, binding.id)
def owner_id(self, tenant_id: str, identity: ResourceIdentity) -> str | None:
return None
diff --git a/api/controllers/openapi/_files.py b/api/controllers/openapi/_files.py
index f5481ec74de..a7f99b0989d 100644
--- a/api/controllers/openapi/_files.py
+++ b/api/controllers/openapi/_files.py
@@ -67,7 +67,7 @@ def _mapping(part: FileStorage, caller: Any) -> FileMapping:
uploaded = upload(part, caller)
return {
"transfer_method": FileTransferMethod.LOCAL_FILE,
- "upload_file_id": str(uploaded.id),
+ "upload_file_id": uploaded.id,
"type": standardize_file_type(extension="." + uploaded.extension, mime_type=uploaded.mime_type),
}
diff --git a/api/repositories/knowledge/dataset_api_key_bindings.py b/api/repositories/knowledge/dataset_api_key_bindings.py
index 68192c376ce..09f7b6e441b 100644
--- a/api/repositories/knowledge/dataset_api_key_bindings.py
+++ b/api/repositories/knowledge/dataset_api_key_bindings.py
@@ -21,17 +21,16 @@ from models.model import ApiToken, DatasetApiTokenBinding
def get_bound_dataset_ids(session: Session, api_token_id: str) -> set[str]:
"""Return the dataset ids a key is scoped to (empty set means unrestricted)."""
- return {
- str(dataset_id)
- for dataset_id in session.scalars(
+ return set(
+ session.scalars(
select(DatasetApiTokenBinding.dataset_id).where(DatasetApiTokenBinding.api_token_id == api_token_id)
).all()
- }
+ )
def list_bindings_by_token(session: Session, token_ids: Iterable[str]) -> dict[str, list[str]]:
"""Group bound dataset ids by api token id for the given tokens."""
- ids = [str(token_id) for token_id in token_ids]
+ ids = list(token_ids)
bindings_by_token: dict[str, list[str]] = {}
if not ids:
return bindings_by_token
@@ -49,12 +48,9 @@ def find_unknown_dataset_ids(session: Session, dataset_ids: list[str], tenant_id
"""Return the dataset ids that do not belong to the tenant (preserving order)."""
if not dataset_ids:
return []
- existing = {
- str(dataset_id)
- for dataset_id in session.scalars(
- select(Dataset.id).where(Dataset.id.in_(dataset_ids), Dataset.tenant_id == tenant_id)
- ).all()
- }
+ existing = set(
+ session.scalars(select(Dataset.id).where(Dataset.id.in_(dataset_ids), Dataset.tenant_id == tenant_id)).all()
+ )
return [dataset_id for dataset_id in dataset_ids if dataset_id not in existing]
@@ -76,7 +72,7 @@ def delete_keys_scoped_only_to(session: Session, dataset_id: str) -> list[str]:
Must run before the dataset row is deleted (so the bindings still exist).
Returns the deleted api_token ids; the caller controls the transaction.
"""
- orphan_ids = [str(token_id) for token_id in session.scalars(token_ids_scoped_only_to(dataset_id)).all()]
+ orphan_ids = list(session.scalars(token_ids_scoped_only_to(dataset_id)).all())
if orphan_ids:
session.execute(delete(ApiToken).where(ApiToken.id.in_(orphan_ids)))
return orphan_ids
diff --git a/api/repositories/oauth_device_token_repository.py b/api/repositories/oauth_device_token_repository.py
index c338c92f7d9..741b316b959 100644
--- a/api/repositories/oauth_device_token_repository.py
+++ b/api/repositories/oauth_device_token_repository.py
@@ -59,7 +59,7 @@ class SQLAlchemyOAuthDeviceTokenRepository:
)
session.add(record)
session.flush()
- token_id = str(record.id)
+ token_id = record.id
session.commit()
rotation = OAuthDeviceTokenRotation(
@@ -150,7 +150,7 @@ class SQLAlchemyOAuthDeviceTokenRepository:
total=total,
items=tuple(
OAuthDeviceSession(
- id=str(record.id),
+ id=record.id,
prefix=record.prefix,
client_id=record.client_id,
device_label=record.device_label,
diff --git a/api/services/app_dsl_service.py b/api/services/app_dsl_service.py
index 526e3862bcb..6ef368bc206 100644
--- a/api/services/app_dsl_service.py
+++ b/api/services/app_dsl_service.py
@@ -556,7 +556,7 @@ class AppDslService:
account.id,
scene=RBACPermission.AGENT_IMPORT_EXPORT_DSL,
resource_type=RBACResourceScope.AGENT if binding is not None else None,
- resource_id=str(binding.id) if binding is not None else None,
+ resource_id=binding.id if binding is not None else None,
)
if not allowed:
raise NoPermissionError("Agent DSL import permission is required to import an Agent App")
diff --git a/api/services/message_service.py b/api/services/message_service.py
index 8bcd98156d2..639b06debbf 100644
--- a/api/services/message_service.py
+++ b/api/services/message_service.py
@@ -303,13 +303,11 @@ class MessageService:
FeedbackCreatedEvent(
context=TelemetryContext(tenant_id=app_model.tenant_id),
payload={
- "message_id": str(message.id),
- "app_id": str(app_model.id) if app_model.id is not None else None,
- "conversation_id": (
- str(message.conversation_id) if message.conversation_id is not None else None
- ),
- "from_end_user_id": str(user.id) if isinstance(user, EndUser) and user.id is not None else None,
- "from_account_id": str(user.id) if isinstance(user, Account) and user.id is not None else None,
+ "message_id": message.id,
+ "app_id": app_model.id,
+ "conversation_id": message.conversation_id,
+ "from_end_user_id": user.id if isinstance(user, EndUser) else None,
+ "from_account_id": user.id if isinstance(user, Account) else None,
"rating": rating.value if rating else None,
"from_source": (
FeedbackFromSource.USER if isinstance(user, EndUser) else FeedbackFromSource.ADMIN
diff --git a/api/services/rbac_resource_service.py b/api/services/rbac_resource_service.py
index a464146ebdb..fa34638f0c6 100644
--- a/api/services/rbac_resource_service.py
+++ b/api/services/rbac_resource_service.py
@@ -37,4 +37,4 @@ class RBACResourceService:
dataset_id = session.scalar(
select(Dataset.id).where(Dataset.pipeline_id == pipeline_id, Dataset.tenant_id == tenant_id)
)
- return None if dataset_id is None else str(dataset_id)
+ return dataset_id
diff --git a/api/tasks/initialize_created_app_rbac_access_task.py b/api/tasks/initialize_created_app_rbac_access_task.py
index 1c3c87a483b..ce1bfaea220 100644
--- a/api/tasks/initialize_created_app_rbac_access_task.py
+++ b/api/tasks/initialize_created_app_rbac_access_task.py
@@ -53,7 +53,7 @@ class _WhitelistResourceKind[ItemT]:
)
if last_id:
stmt = stmt.where(self.model.id > last_id)
- ids = [str(resource_id) for resource_id in db.session().scalars(stmt).all()]
+ ids = list(db.session().scalars(stmt).all())
if not ids:
return
yield ids