I get an error {'loc': ('response', 'piegraphdata'), 'msg': 'value is not a valid list', 'type': 'type_error.list'}
on running the below code. I tried a number of variations but all give the same error. This is what I currently have:
@router.post("/graph-view/", response_model=GraphViewOutput)
async def get_graph_for_file(input: GraphInput) -> Any:
(some data is retrieved from a database)
print(query_graph_result)
return {"piegraphdata": query_graph_result}
The models I’m using are:
from pydantic import BaseModel
from typing import List, Union
class GraphInput(BaseModel):
file_name: str = ""
target_collection: list = []
class GraphViewOutput(BaseModel):
piegraphdata: List[List[Union[str, int]]]
The print statement gives me the correct output:
[['ud', 3334], ['tika-vin', 1102], ['tika-s', 1712], ['kv', 179], ['pp', 188]]
I tried various ways of writing class GraphViewOutput
but I cannot find out how to write this correctly.
What I need is it to correctly output:
{"piegraphdata": [['ud', 3334], ['tika-vin', 1102], ['tika-s', 1712], ['kv', 179], ['pp', 188]]}
What am I doing wrong?
Thank you for your help.