✨ Add support for dependencies in WebSocket routes#4534
Conversation
10dc6e9 to
0ac85d4
Compare
0ac85d4 to
4d892d9
Compare
|
Hello! Is there anything missing on this PR? |
64a3946 to
62d72b5
Compare
|
Thank you for the reviews, @BilalAlpaslan @cikay. I just fixed the merge conflicts, it should be ready for merging |
I've been using dependencies to handle authentication. But imagine my surprise when I realized my websocket endpoint wasn't authenticated at all? This commit cherry-picks the `dependencies` chunks from `APIRoute` into `APIWebSocketRoute` I also made a few minor style nit-picks
31a89c4 to
0fc264d
Compare
|
@tiangolo, sorry to call you directly, but can I get your eyes on this? This is a straightforward issue, but it has been bugging me a lot in the last month 😅 Thank you 🙏 |
|
Anything missing from this change? How can I get it merged? |
|
📝 Docs preview for commit 6453788 at: https://62a95f500fa552369a8a9c11--fastapi.netlify.app |
6453788 to
0925718
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #4534 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 540 541 +1
Lines 13969 14001 +32
=========================================
+ Hits 13969 14001 +32
☔ View full report in Codecov by Sentry. |
0925718 to
73249da
Compare
|
📝 Docs preview for commit 73249da at: https://62a96d422ba68a456ea1be02--fastapi.netlify.app |
|
📝 Docs preview for commit 3945a32 at: https://6337d198c51f172ca119d1f5--fastapi.netlify.app |
|
📝 Docs preview for commit e4ddcb8 at: https://633b8d39f6ae0b0073aa6272--fastapi.netlify.app |
|
📝 Docs preview for commit 5943bae at: https://634eff6b41393725675bf3ea--fastapi.netlify.app |
|
📝 Docs preview for commit ccc1987 at: https://6355f671a4e4cf7923aace28--fastapi.netlify.app |
|
📝 Docs preview for commit f2541d2 at: https://639ce37dca15d5006470360d--fastapi.netlify.app |
|
📝 Docs preview for commit 275208e at: https://63dfcc686a21a87de30b11e3--fastapi.netlify.app |
|
ping? |
|
Is there any progress about this issue? |
|
📝 Docs preview for commit a463414 at: https://64861d40ff845b421d97876c--fastapi.netlify.app |
dependencies in websocket routesdependencies in WebSocket routes
|
Great, thank you @paulo-raca! 🚀 🙇 This will be available in the next version, FastAPI 0.97.0, released in the next hours (or tomorrow). 🎉 |
|
Neat, thank you |
|
For me this was a breaking change because some dependencies I have on the router itself had |
|
@bastianh and/or @gjanezic, please create a new discussion with a simple example I can copy paste and replicate your issue: https://github.com/tiangolo/fastapi/discussions/categories/questions 🙏 |
I've been using dependencies to handle authentication.
But imagine my surprise when I realized my websocket endpoint wasn't authenticated at all?
This commit cherry-picks the
dependencieschunks fromAPIRouteintoAPIWebSocketRouteI also made a few minor style nit-picks.
Here is a much-simplified code that demonstrates the issue:
As expected, accessing "/get" results in 401 error:
However the websocket endpoint remains accessible:
After applying the patch, the dependencies execute successfully:
Interestingly the websocket connection fails with code 500 instead of 401. I have addressed it into a separate PR to starlette