Skip to content

Best practice to acessing context of a request outside a controller? #1100

Answered by albcunha
albcunha asked this question in Q&A
Discussion options

You must be logged in to vote

In case anyone stumbles over this, implementations using contextvars wont work in some cases. As we rely on asyncio.to_thread() we cant get returns back. Backpropagation is not possible. This is discussed here: https://discuss.python.org/t/back-propagation-of-contextvar-changes-from-worker-threads/15928/24 . Maybe in the future it will be implemented.
I wasn´t fully able to explain our situation. Sometimes we have a lot of chained functions. Passing an argument through 6-8 functions/classes seems too much. We chose a simpler approach, we will update the database with the warnings and retrieve it at the end, as there won´t be many calls to each report generation, it´s easier to implement.

Replies: 7 comments 9 replies

Comment options

You must be logged in to vote
2 replies
@albcunha
Comment options

@provinzkraut
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@albcunha
Comment options

@infohash
Comment options

Comment options

You must be logged in to vote
4 replies
@peterschutt
Comment options

@albcunha
Comment options

@Goldziher
Comment options

@provinzkraut
Comment options

Comment options

You must be logged in to vote
1 reply
@provinzkraut
Comment options

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 albcunha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants