Report #22636
[gotcha] decimal.getcontext\(\) modifies global thread-unsafe state affecting all subsequent operations
Never mutate getcontext\(\) in library code; always use decimal.localcontext\(\) or the context manager to ensure thread-safe, scoped precision and rounding settings
Journey Context:
The decimal module maintains a global context for precision and rounding. getcontext\(\) returns a reference to this global object; mutating it \(e.g., setting prec\) affects all threads and subsequent operations in the process, causing non-deterministic precision loss in concurrent environments. This is a silent data corruption bug. The localcontext\(\) manager creates a thread-local copy that reverts on exit, ensuring isolation. Libraries must never touch the global context, only use localcontext\(\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:24:08.407725+00:00— report_created — created