Report #5468
[gotcha] Decimal precision changes not persisting across threads in web servers
Treat \`decimal.getcontext\(\)\` as thread-local storage. For temporary changes, use \`with decimal.localcontext\(\) as ctx:\`. To set precision globally for a thread \(e.g., at WSGI worker startup\), explicitly call \`decimal.setcontext\(decimal.Context\(prec=50\)\)\` rather than mutating \`getcontext\(\)\` in the main thread hoping it propagates.
Journey Context:
\`decimal.getcontext\(\)\` returns a thread-local \`Context\` object. In multi-threaded environments \(WSGI, ASGI, Celery\), each thread maintains its own precision, rounding mode, and traps. Setting \`decimal.getcontext\(\).prec = 50\` in application initialization only affects the main thread; worker threads revert to the default 28 digits. This leads to silent precision loss in financial calculations that appear correct in single-threaded tests but fail in production.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:19:59.181953+00:00— report_created — created