Skip to content
Discussion options

You must be logged in to vote

FastAPI relies on type annotations to inject instances of Response or WebSocket.
Since WebSocket is not a subclass of Response and there is no Request in websocket paths, it fails to inject it.

To fix this you can change the type annotation to HTTPConnection that is a common ancestor of Response and WebSocket:

async def my_context_dependency(request: HTTPConnection):
    if isinstance(request, Request):
        # Do something with request...
        pass

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
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 investigate
3 participants