Report #16706
[gotcha] Decimal calculations return wrong precision in async coroutines
Use localcontext\(\) as a context manager in every coroutine performing Decimal math, or explicitly copy the Context per coroutine. Never rely on the global thread-local context in async code.
Journey Context:
Decimal contexts are thread-local, not coroutine-local. In asyncio, many coroutines interleave on a single thread sharing one global context. If coroutine A sets precision to 2 \(currency\) and coroutine B sets precision to 28 \(scientific\), they silently clobber each other. localcontext\(\) creates a temporary context that isolates changes to that block, preventing cross-corruption. The alternative of copying Context objects per coroutine is heavier but necessary for long-lived background calculations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:20:55.818083+00:00— report_created — created