diff --git a/src/backend/base/langflow/api/v1/flows.py b/src/backend/base/langflow/api/v1/flows.py index d4614c36cbab..2f350222b7d4 100644 --- a/src/backend/base/langflow/api/v1/flows.py +++ b/src/backend/base/langflow/api/v1/flows.py @@ -17,13 +17,7 @@ from sqlmodel import and_, col, select from sqlmodel.ext.asyncio.session import AsyncSession -from langflow.api.utils import ( - CurrentActiveUser, - DbSession, - cascade_delete_flow, - remove_api_keys, - validate_is_component, -) +from langflow.api.utils import CurrentActiveUser, DbSession, cascade_delete_flow, remove_api_keys, validate_is_component from langflow.api.v1.schemas import FlowListCreate from langflow.initial_setup.constants import STARTER_FOLDER_NAME from langflow.services.database.models.flow import Flow, FlowCreate, FlowRead, FlowUpdate @@ -221,17 +215,7 @@ async def read_flows( if remove_example_flows and starter_folder_id: flows = [flow for flow in flows if flow.folder_id != starter_folder_id] if header_flows: - return [ - { - "id": flow.id, - "name": flow.name, - "folder_id": flow.folder_id, - "is_component": flow.is_component, - "description": flow.description, - "endpoint_name": flow.endpoint_name, - } - for flow in flows - ] + return [FlowHeader.model_validate(flow, from_attributes=True) for flow in flows] return flows stmt = stmt.where(Flow.folder_id == folder_id) diff --git a/src/backend/base/langflow/services/database/models/flow/model.py b/src/backend/base/langflow/services/database/models/flow/model.py index 7fc64e078723..132ea94de8b1 100644 --- a/src/backend/base/langflow/services/database/models/flow/model.py +++ b/src/backend/base/langflow/services/database/models/flow/model.py @@ -9,7 +9,7 @@ from emoji import purely_emoji from fastapi import HTTPException, status from loguru import logger -from pydantic import BaseModel, field_serializer, field_validator +from pydantic import BaseModel, field_serializer, field_validator, model_validator from sqlalchemy import Text, UniqueConstraint from sqlmodel import JSON, Column, Field, Relationship, SQLModel @@ -198,30 +198,21 @@ class FlowRead(FlowBase): class FlowHeader(BaseModel): - """Model representing a header for a flow - Without the data. - - Attributes: - ----------- - id : UUID - Unique identifier for the flow. - name : str - The name of the flow. - folder_id : UUID | None, optional - The ID of the folder containing the flow. None if not associated with a folder. - is_component : bool | None, optional - Flag indicating whether the flow is a component. - endpoint_name : str | None, optional - The name of the endpoint associated with this flow. - description : str | None, optional - A description of the flow. - """ + """Model representing a header for a flow - Without the data.""" - id: UUID - name: str - folder_id: UUID | None = None - is_component: bool | None = None - endpoint_name: str | None = None - description: str | None = None + id: UUID = Field(description="Unique identifier for the flow") + name: str = Field(description="The name of the flow") + folder_id: UUID | None = Field( + None, description="The ID of the folder containing the flow. None if not associated with a folder" + ) + is_component: bool | None = Field(None, description="Flag indicating whether the flow is a component") + endpoint_name: str | None = Field(None, description="The name of the endpoint associated with this flow") + description: str | None = Field(None, description="A description of the flow") + + @model_validator(mode="before") + @classmethod + def validate_flow_header(cls, data: dict): + return data class FlowUpdate(SQLModel):