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.

example add more type check (#24999)

Asuka Minatoa418c43d32b0
diff --git a/api/models/base.py b/api/models/base.py
index bd120f5487c..76848825fef 100644
--- a/api/models/base.py
+++ b/api/models/base.py
@@ -1,7 +1,15 @@
-from sqlalchemy.orm import DeclarativeBase
+from sqlalchemy.orm import DeclarativeBase, MappedAsDataclass
from models.engine import metadata
class Base(DeclarativeBase):
metadata = metadata
+
+
+class TypeBase(MappedAsDataclass, DeclarativeBase):
+ """
+ This is for adding type, after all finished, rename to Base.
+ """
+
+ metadata = metadata
diff --git a/api/models/tools.py b/api/models/tools.py
index d88d817374d..08219ebd2fc 100644
--- a/api/models/tools.py
+++ b/api/models/tools.py
@@ -14,7 +14,7 @@ from core.mcp.types import Tool
from core.tools.entities.common_entities import I18nObject
from core.tools.entities.tool_bundle import ApiToolBundle
from core.tools.entities.tool_entities import ApiProviderSchemaType, WorkflowToolParameterConfiguration
-from models.base import Base
+from models.base import Base, TypeBase
from .engine import db
from .model import Account, App, Tenant
@@ -160,7 +160,7 @@ class ApiToolProvider(Base):
return db.session.query(Tenant).where(Tenant.id == self.tenant_id).first()
-class ToolLabelBinding(Base):
+class ToolLabelBinding(TypeBase):
"""
The table stores the labels for tools.
"""
@@ -171,7 +171,7 @@ class ToolLabelBinding(Base):
sa.UniqueConstraint("tool_id", "label_name", name="unique_tool_label_bind"),
)
- id: Mapped[str] = mapped_column(StringUUID, server_default=sa.text("uuid_generate_v4()"))
+ id: Mapped[str] = mapped_column(StringUUID, server_default=sa.text("uuid_generate_v4()"), init=False)
# tool id
tool_id: Mapped[str] = mapped_column(String(64), nullable=False)
# tool type