DO NOT FORK, CLICK "Use this template" - The base to start an openapi project featuring: SQLModel, Typer, FastAPI, JWT Token Auth, Interactive Shell, Management Commands.
I am using this amazing template to build an app I followed the first steps and I got an error while running the tests;
When I run make test I get a "fastapi.exceptions.FastAPIError" in a route definition but if I remove the dependency to AuthenticatedUser the error disapears.
@router.post(
"/", response_model=ContentResponse, dependencies=[AuthenticatedUser],
)
async def create_content(
*,
session: Session = ActiveSession,
request: Request,
content: ContentIncoming,
):
# set the ownsership of the content to the current user
db_content = Content.from_orm(content)
user: User = get_current_user(request=request)
db_content.user_id = user.id
session.add(db_content)
session.commit()
session.refresh(db_content)
return db_content
and the whole exception is
ImportError while loading conftest '/home/konradzuse/PycharmProjects/app-service/application-service/tests/conftest.py'.
tests/conftest.py:11: in
from app_service import app, settings, db # noqa
app_service/init.py:1: in
from .app import app
app_service/app.py:9: in
from .routes import main_router
app_service/routes/init.py:5: in
from .content import router as content_router
app_service/routes/content.py:35: in
@router.patch(
...
raise fastapi.exceptions.FastAPIError(
E fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that typing.Optional[starlette.requests.Request] is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None.
I tried to use response_model = None but still got the same error. I looked for similar questions but normally they are related to the model itself. I hope somone can cast some light.
I am using this amazing template to build an app I followed the first steps and I got an error while running the tests; When I run
make test
I get a "fastapi.exceptions.FastAPIError" in a route definition but if I remove the dependency to AuthenticatedUser the error disapears.This is the route where it happens https://github.com/rochacbruno/fastapi-project-template/blob/8e0bc818a1b797b06f94f4b8b9f4229a059027fc/project_name/routes/content.py#L36
and the whole exception is
ImportError while loading conftest '/home/konradzuse/PycharmProjects/app-service/application-service/tests/conftest.py'. tests/conftest.py:11: in
from app_service import app, settings, db # noqa
app_service/init.py:1: in
from .app import app
app_service/app.py:9: in
from .routes import main_router
app_service/routes/init.py:5: in
from .content import router as content_router
app_service/routes/content.py:35: in
@router.patch(
...
raise fastapi.exceptions.FastAPIError(
E fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that typing.Optional[starlette.requests.Request] is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None.
I tried to use response_model = None but still got the same error. I looked for similar questions but normally they are related to the model itself. I hope somone can cast some light.
Thanks beforehand!