Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add model validator to FlowHeader model and fix response handling #5355

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions src/backend/base/langflow/api/v1/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 15 additions & 24 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,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

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