From 2feeeb9ecd78d9f659c1b73dbe50ef47c2e36134 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 6 Jun 2023 17:37:05 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(flow.py):=20make=20flow=20fi?= =?UTF-8?q?eld=20optional=20to=20allow=20creation=20of=20flows=20without?= =?UTF-8?q?=20a=20flow=20=F0=9F=A7=AA=20test(test=5Fdatabase.py):=20add=20?= =?UTF-8?q?test=20case=20for=20creating=20flows=20without=20a=20flow=20The?= =?UTF-8?q?=20flow=20field=20is=20now=20optional=20to=20allow=20creation?= =?UTF-8?q?=20of=20flows=20without=20a=20flow.=20This=20is=20useful=20when?= =?UTF-8?q?=20creating=20a=20flow=20that=20will=20be=20populated=20later.?= =?UTF-8?q?=20A=20test=20case=20was=20added=20to=20ensure=20that=20flows?= =?UTF-8?q?=20can=20be=20created=20without=20a=20flow.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/database/models/flow.py | 4 +++- tests/test_database.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/database/models/flow.py b/src/backend/langflow/database/models/flow.py index 0b71463a0..6305de3cc 100644 --- a/src/backend/langflow/database/models/flow.py +++ b/src/backend/langflow/database/models/flow.py @@ -12,11 +12,13 @@ from langflow.database.models.flow_style import FlowStyle, FlowStyleRead class FlowBase(SQLModelSerializable): name: str = Field(index=True) - flow: Dict = Field(default_factory=dict, sa_column=Column(JSON)) + flow: Optional[Dict] = Field(default_factory=dict, sa_column=Column(JSON)) @validator("flow") def validate_json(v): # dict_keys(['description', 'name', 'id', 'data']) + if not v: + return v if not isinstance(v, dict): raise ValueError("Flow must be a valid JSON") if "description" not in v.keys(): diff --git a/tests/test_database.py b/tests/test_database.py index 8b680129f..516c04ade 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -38,6 +38,12 @@ def test_create_flow(client: TestClient, json_flow: str): assert response.status_code == 200 assert response.json()["name"] == flow.name assert response.json()["flow"] == flow.flow + # flow is optional so we can create a flow without a flow + flow = FlowCreate(name="Test Flow") + response = client.post("api/v1/flows/", json=flow.dict(exclude_unset=True)) + assert response.status_code == 200 + assert response.json()["name"] == flow.name + assert response.json()["flow"] == flow.flow def test_read_flows(client: TestClient, json_flow: str):