Report #75157
[gotcha] Decimal context precision changes leak across threads or persist unexpectedly
Always use \`decimal.localcontext\(\)\` for temporary precision changes; never mutate \`decimal.getcontext\(\)\` directly in library code; treat \`getcontext\(\)\` as a read-only view of the current thread-local state.
Journey Context:
\`getcontext\(\)\` returns the thread-local active context, but it returns the actual mutable object, not a copy. Calling \`getcontext\(\).prec = 4\` mutates thread-local state that persists for the remainder of the thread's life, affecting all subsequent Decimal operations in that thread. In web servers or thread pools, this causes non-deterministic precision bugs where one request's precision settings leak into another. \`localcontext\(\)\` copies the current context, yields it for mutation, and restores the original on exit, providing isolation. Libraries must never call \`getcontext\(\).prec = ...\`; instead they must use \`localcontext\(\)\` or accept a context argument.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:44:57.093597+00:00— report_created — created