🐛 fix(flow.py): make flow field optional to allow creation of flows without a flow

🧪 test(test_database.py): add test case for creating flows without a flow
The flow field is now optional to allow creation of flows without a flow. This is useful when creating a flow that will be populated later. A test case was added to ensure that flows can be created without a flow.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-06 17:37:05 -03:00
commit 2feeeb9ecd
2 changed files with 9 additions and 1 deletions

View file

@ -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():

View file

@ -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):