[Question] Had some queries around the context propagation example
Hi, was just implementing a context propagation interceptor based on this sample: https://github.com/temporalio/samples-python/blob/main/context_propagation/README.md
After a bit of experimentation, it seems like the the contextvar value is automatically restored to the previous value during multiple concurrent workflow runs and even after an activity finishes executing (if the var was updated inside the activity).
I was wondering if the ContextVar.reset() usage in the sample is redundant? or are there scenarios where it might have an effect?
I'm using a thread pool executor for my worker, so perhaps thats why it seems like ContextVar.reset() does not do anything? https://github.com/temporalio/sdk-python/issues/263
Would it be safe to remove the resetting part when using a thread pool executor for activity tasks? And for workflows in general if I don't want the context vars state to leak between them?
I was wondering if the ContextVar.reset() usage in the sample is redundant? or are there scenarios where it might have an effect?
It may seem redundant for activities only because if it was left over from a previous activity on that thread, we overwrite it. However, if the header never comes in, then we don't overwrite it. So if you had one activity with a context var from the header and didn't reset it, then you had another activity without the header at all and reuses the previous activity's thread, you'd still see the context var from the previous activity. async def activities of course don't have this concern because context vars are local to the task instead of thread then.
For workflows it is less necessary because it's isolated in its asyncio task.
Regardless, it's simply good practice to reset context vars you set. What is the reason to want to remove reset?