Talking about the Serverless Apps with FastAPI, DynamoDB, and Vue course. I'm currently stuck on section "API" from Part 1, which seems to be pydantic related.
When running the tests with $ poetry run pytest tests.py
a ValidationError
rises with the following:
> ???
E pydantic.error_wrappers.ValidationError: 1 validation error for APITaskList
E results -> 0
E value is not a valid dict (type=type_error.dict)
pydantic/main.py:341: ValidationError
============================================= short test summary info ============================
FAILED tests.py::test_list_open_tasks - pydantic.error_wrappers.ValidationError: 1 validation error for APITaskList
I was expecting a succesful execution, since I've reproduced all of the course steps accordingly. But anyways, here are some extra info that might help:
Failing command (from tests.py): response = client.get("/api/open-tasks", headers={"Authorization": id_token})
- where client is a TestClient
fixtture.
Api route ("api/open-tasks"):
@app.get("/api/open-tasks", response_model=APITaskList)
def open_tasks(
user_email: str = Depends(get_user_email),
task_store: TaskStore = Depends(get_task_store),
):
return APITaskList(results=task_store.list_open(owner=user_email))
APITaskList
schema:class APITaskList(BaseModel):
results: list[APITask]
class Config:
orm_mode = True
APITask
schema:class APITask(BaseModel):
id: UUID
title: str
status: TaskStatus
owner: str
class Config:
orm_mode: True
As pointed out on @M.O.'s comment:
... you have
orm_mode: True
instead oform_mode = True
inAPITask.Config
.
Test passed successfully after this fix.