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 132ea94de..7b154381c 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,12 @@ import emoji from emoji import purely_emoji from fastapi import HTTPException, status from loguru import logger -from pydantic import BaseModel, field_serializer, field_validator, model_validator +from pydantic import ( + BaseModel, + ValidationInfo, + field_serializer, + field_validator, +) from sqlalchemy import Text, UniqueConstraint from sqlmodel import JSON, Column, Field, Relationship, SQLModel @@ -203,16 +208,20 @@ class FlowHeader(BaseModel): 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" + 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") + data: dict | None = Field(None, description="The data of the component, if is_component is True") - @model_validator(mode="before") + @field_validator("data", mode="before") @classmethod - def validate_flow_header(cls, data: dict): - return data + def validate_flow_header(cls, value: dict, info: ValidationInfo): + if not info.data["is_component"]: + return None + return value class FlowUpdate(SQLModel):