fix: add data field to returned object on flowheader if flow is a component (#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>
This commit is contained in:
parent
9fc3601df8
commit
1daf915169
1 changed files with 14 additions and 5 deletions
|
|
@ -9,7 +9,12 @@ import emoji
|
||||||
from emoji import purely_emoji
|
from emoji import purely_emoji
|
||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
from loguru import logger
|
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 sqlalchemy import Text, UniqueConstraint
|
||||||
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
||||||
|
|
||||||
|
|
@ -203,16 +208,20 @@ class FlowHeader(BaseModel):
|
||||||
id: UUID = Field(description="Unique identifier for the flow")
|
id: UUID = Field(description="Unique identifier for the flow")
|
||||||
name: str = Field(description="The name of the flow")
|
name: str = Field(description="The name of the flow")
|
||||||
folder_id: UUID | None = Field(
|
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")
|
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")
|
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")
|
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
|
@classmethod
|
||||||
def validate_flow_header(cls, data: dict):
|
def validate_flow_header(cls, value: dict, info: ValidationInfo):
|
||||||
return data
|
if not info.data["is_component"]:
|
||||||
|
return None
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class FlowUpdate(SQLModel):
|
class FlowUpdate(SQLModel):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue