Report #5674
[gotcha] Decimal calculations suddenly lose precision or change rounding mode in long-running processes
Never modify decimal.getcontext\(\) directly in library code. Always use decimal.localcontext\(\) as a context manager for temporary precision changes.
Journey Context:
decimal.getcontext\(\) returns the thread-local context. Modifying it affects ALL subsequent Decimal operations in that thread, including code that runs much later. This causes 'action at a distance' bugs where one module's precision change corrupts calculations in unrelated modules. localcontext\(\) creates a temporary context that restores the original state on exit, providing isolation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:51:04.783816+00:00— report_created — created