📝 Upate docs for advanced dependencies with `yield`, noting the changes in 0.121.0, adding `scope` (#14287)

This commit is contained in:
Sebastián Ramírez 2025-11-03 14:19:58 +01:00 committed by GitHub
parent 4efae81a76
commit 289b4aa2fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 1 deletions

View File

@ -70,12 +70,22 @@ If you understood all this, you already know how those utility tools for securit
You most probably don't need these technical details. You most probably don't need these technical details.
These details are useful mainly if you had a FastAPI application older than 0.118.0 and you are facing issues with dependencies with `yield`. These details are useful mainly if you had a FastAPI application older than 0.121.0 and you are facing issues with dependencies with `yield`.
/// ///
Dependencies with `yield` have evolved over time to account for the different use cases and to fix some issues, here's a summary of what has changed. Dependencies with `yield` have evolved over time to account for the different use cases and to fix some issues, here's a summary of what has changed.
### Dependencies with `yield` and `scope` { #dependencies-with-yield-and-scope }
In version 0.121.0, FastAPI added support for `Depends(scope="function")` for dependencies with `yield`.
Using `Depends(scope="function")`, the exit code after `yield` is executed right after the *path operation function* is finished, before the response is sent back to the client.
And when using `Depends(scope="request")` (the default), the exit code after `yield` is executed after the response is sent.
You can read more about it in the docs for [Dependencies with `yield` - Early exit and `scope`](../tutorial/dependencies/dependencies-with-yield.md#early-exit-and-scope).
### Dependencies with `yield` and `StreamingResponse`, Technical Details { #dependencies-with-yield-and-streamingresponse-technical-details } ### Dependencies with `yield` and `StreamingResponse`, Technical Details { #dependencies-with-yield-and-streamingresponse-technical-details }
Before FastAPI 0.118.0, if you used a dependency with `yield`, it would run the exit code after the *path operation function* returned but right before sending the response. Before FastAPI 0.118.0, if you used a dependency with `yield`, it would run the exit code after the *path operation function* returned but right before sending the response.