KITFORMA · EDITORIAL ANSWER
Why should async request metadata use ContextVar instead of a global variable?
KitForma editorial guide. Concurrent requests share module globals, so one request can overwrite another’s correlation ID or locale while both are active.
Step-by-step answer
ContextVar for context-local metadata and reset it with the token returned by set in a finally block. Test two interleaved tasks with different request IDs and confirm logs never cross-contaminate. Context propagation across threads, custom executors and detached tasks requires checking the actual API behavior. Context variables are not persistent storage or an authorization source. Security decisions should use the validated request identity explicitly rather than trusting mutable diagnostic metadata.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.