Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

✨ Add support for raising exceptions (includingHTTPException) in dependencies withyield in the exit code, do not support them in background tasks#10831

Merged
tiangolo merged 8 commits intomasterfrom
dependencies-refactor-end-before-response
Dec 25, 2023
Merged

✨ Add support for raising exceptions (includingHTTPException) in dependencies withyield in the exit code, do not support them in background tasks#10831
tiangolo merged 8 commits intomasterfrom
dependencies-refactor-end-before-response

Conversation

@tiangolo
Copy link
Member

@tiangolotiangolo commentedDec 25, 2023
edited
Loading

✨ Add support for raising exceptions (includingHTTPException) in dependencies withyield in the exit code, do not support them in background tasks.

This moves theAsyncExitStack from a middleware that would run the exit code after the response is sent and background tasks are executed to inside of the dependencies logic, after creating the response but before sending it.

So, now dependencies with yield are nicely wrapped by exception handlers, middleware, and the request-response cycle.

Before they would be executed after background tasks finished. The intention was to allow sharing the same database connection, but this would mean holding a resource (e.g. DB connection) until after the request travels through the network, it would prevent supporting raising exceptions afteryield, and allowed dangerously coupling logic related to resources from dependencies withyield with background tasks (e.g. hard to test).

This will also enable several new features and changes, including upgrades to the recent versions of Starlette, and/or making background tasks independent of the request-response lifecycle, etc.

adriangb reacted with rocket emoji
@tiangolotiangolo added the featureNew feature or request labelDec 25, 2023
@tiangolo
Copy link
MemberAuthor

📝 Docs preview for commit01b1fe0 at:https://48e522da.fastapitiangolo.pages.dev

@tiangolo
Copy link
MemberAuthor

📝 Docs preview for commitc239211 at:https://775033af.fastapitiangolo.pages.dev

@tiangolotiangolo marked this pull request as ready for reviewDecember 25, 2023 17:57
@tiangolotiangolo merged commita4aa79e intomasterDec 25, 2023
@tiangolotiangolo deleted the dependencies-refactor-end-before-response branchDecember 25, 2023 17:57
nilslindemann pushed a commit to nilslindemann/fastapi that referenced this pull requestDec 26, 2023
tiangolo added a commit that referenced this pull requestSep 21, 2025
…tion`) in dependencies with `yield` in the exit code, do not support them in background tasks (#10831)"This reverts commita4aa79e.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

featureNew feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@tiangolo

[8]ページ先頭

©2009-2026 Movatter.jp