🐛 fix(database.py): handle case where data does not contain "flows" key
✨ feat(database.py): add default argument to json.dumps to handle datetime objects 🚨 test(database.py): add tests for batch flow creation, file upload, and file download The fix in database.py handles the case where the data dictionary does not contain the "flows" key. This is important because the code assumes that the "flows" key is present and will raise an exception if it is not. The fix adds a check to see if the "flows" key is present and if not, it creates a new FlowListCreate object with the data as a list of FlowCreate objects. The feature in database.py adds a default argument to the json.dumps function to handle datetime objects. This is important because the default json encoder does not handle datetime objects and will raise an exception if it encounters one. The tests in test_database.py cover the batch creation of flows, uploading a file containing flows, and downloading a file containing flows. These tests ensure that the endpoints are working as expected and that the data is being handled correctly.
This commit is contained in:
parent
ce2f0ebf48
commit
5a46c1e1a0
3 changed files with 86 additions and 3 deletions
|
|
@ -92,7 +92,10 @@ async def upload_file(
|
|||
"""Upload flows from a file."""
|
||||
contents = await file.read()
|
||||
data = json.loads(contents)
|
||||
flow_list = FlowListCreate(**data)
|
||||
if "flows" in data:
|
||||
flow_list = FlowListCreate(**data)
|
||||
else:
|
||||
flow_list = FlowListCreate(flows=[FlowCreate(**flow) for flow in data])
|
||||
return create_flows(session=session, flow_list=flow_list)
|
||||
|
||||
|
||||
|
|
@ -100,4 +103,4 @@ async def upload_file(
|
|||
async def download_file(*, session: Session = Depends(get_session)):
|
||||
"""Download all flows as a file."""
|
||||
flows = read_flows(session=session)
|
||||
return {"file": json.dumps([flow.dict() for flow in flows])}
|
||||
return {"file": json.dumps([flow.dict() for flow in flows], default=str)}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ async def get_load(
|
|||
if flow_obj is None:
|
||||
raise ValueError(f"Flow {flow_id} not found")
|
||||
graph_data: GraphData = json.loads(flow_obj.flow)
|
||||
data = graph_data.dict()
|
||||
data = graph_data.get("data")
|
||||
response = process_graph_cached(data, predict_request.message)
|
||||
return PredictResponse(
|
||||
result=response.get("result", ""),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue