Skip to content

Yield dependency doesn't allow to add a background task in its closing code #6871

Answered by tiangolo
and-semakin asked this question in Questions
Discussion options

You must be logged in to vote

Yep, dependencies with yield are closed after background tasks are done. This was to be able to use the same DB session.

But I see that in some cases it would make sense to close them before the response is sent. That's something I've been considering and thinking about how to properly implement.

All that is documented a bit here, wth a pretty diagram and everything: https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-with-yield/#dependencies-with-yield-and-httpexception

Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I'm checking each one in order.

Replies: 4 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 Kludex
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
3 participants
Converted from issue

This discussion was converted from issue #2866 on February 27, 2023 23:16.