Skip to content

Commit

Permalink
fix: add data field to returned object on flowheader if flow is a com…
Browse files Browse the repository at this point in the history
…ponent (#5373)

* Fixed FlowHeader model validator, adding data and removing it if flow is not a component

* [autofix.ci] apply automated fixes

* Fixed flowheader to use fieldvalidator instead of modelvalidator

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
lucaseduoli and autofix-ci[bot] authored Dec 23, 2024
1 parent 9fc3601 commit 1daf915
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/backend/base/langflow/services/database/models/flow/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1daf915

Please sign in to comment.