Skip to content
Discussion options

You must be logged in to vote

Thanks for tagging me.

Why this is an error

The reason is that an annotation like Annotated[fastapi.Request, fastapi.Depends(custom_request)] is ambiguous. There are two conflicting behaviors here:

  1. If the type of the parameter is Request, FastAPI will inject the request object
  2. If the parameter has a Depends, FastAPI will resolve the dependency and inject that.

Prior to #4871, FastAPI would arbitrarily choose one over the other, but this was not documented. That PR changed it to an error if the annotation would be ambiguous.

How to avoid the error

In your case, it does indeed seem that you create a dependency that returns a Request, so it's hard to avoid the ambiguity. However, I think y…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nzig
Comment options

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants