🐛 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:
parent
1d33933d64
commit
2feeeb9ecd
2 changed files with 9 additions and 1 deletions
|
|
@ -12,11 +12,13 @@ from langflow.database.models.flow_style import FlowStyle, FlowStyleRead
|
||||||
|
|
||||||
class FlowBase(SQLModelSerializable):
|
class FlowBase(SQLModelSerializable):
|
||||||
name: str = Field(index=True)
|
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")
|
@validator("flow")
|
||||||
def validate_json(v):
|
def validate_json(v):
|
||||||
# dict_keys(['description', 'name', 'id', 'data'])
|
# dict_keys(['description', 'name', 'id', 'data'])
|
||||||
|
if not v:
|
||||||
|
return v
|
||||||
if not isinstance(v, dict):
|
if not isinstance(v, dict):
|
||||||
raise ValueError("Flow must be a valid JSON")
|
raise ValueError("Flow must be a valid JSON")
|
||||||
if "description" not in v.keys():
|
if "description" not in v.keys():
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,12 @@ def test_create_flow(client: TestClient, json_flow: str):
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json()["name"] == flow.name
|
assert response.json()["name"] == flow.name
|
||||||
assert response.json()["flow"] == flow.flow
|
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):
|
def test_read_flows(client: TestClient, json_flow: str):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue