You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm facing an issue when using Pydantic with FastAPI route decorated with pydantic + Dishka
FastAPIError: Invalid args for response field! Hint: check that typing.Annotated[api.repository.UserRepository, FromComponent(component='')] 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.
The error seems to be only when using FastAPI route decorator like: @app.get("/users/{user_id}", response_model=UserDTO)
If registration is done through add_api_route, Pydantic does not raise exception anymore: app.add_api_route("/users/{user_id}", get_user_by_id, methods=["GET"], response_model=UserDTO)
Moreover, Dishka seems to not support FastAPI in sync mode, when using an injection on a sync endpoint, it raises: TypeError: object list can't be used in 'await' expression from dishka/integrations/base.py:192 (as my endpoint return a list of object)
The method setup_dishka seems to take only AsyncContainer as argument
The text was updated successfully, but these errors were encountered:
Did you forget @inject decorator? It is requried unless you explicitly enable autoinject which is not so trivial in fastapi.
We do not support sync mode yet. Actually, I do not think that using fastapi with sync view is a good idea - you loose all asyncio features and get its problems + additional. If you really need sync views I'd recommend using some WSGI-framerwork (not ASGI)
The problem with sync/async fastapi is mostly in mixing the both approaches. We can try to support sync-only mode, but anyway it looks like some guys will try to use async containers in sync code and vice versa.
I did use the @inject decorator, I think all of this come from the fact I'm using sync mode. Agree that sync mode is not ideal in fastapi, but I've a large codebase already written in sync mode with some underlying libs without asyncio support yet.
Is there any plan to support sync mode? I would be interested to bring such contrib.
Hi,
I'm facing an issue when using Pydantic with FastAPI route decorated with pydantic + Dishka
The error seems to be only when using FastAPI route decorator like:
@app.get("/users/{user_id}", response_model=UserDTO)
If registration is done through
add_api_route
, Pydantic does not raise exception anymore:app.add_api_route("/users/{user_id}", get_user_by_id, methods=["GET"], response_model=UserDTO)
Moreover, Dishka seems to not support FastAPI in sync mode, when using an injection on a sync endpoint, it raises:
TypeError: object list can't be used in 'await' expression
fromdishka/integrations/base.py:192
(as my endpoint return a list of object)The method setup_dishka seems to take only
AsyncContainer
as argumentThe text was updated successfully, but these errors were encountered: