Report #38669
[gotcha] decimal.Decimal calculations lose precision or behave differently across modules
Use \`localcontext\(\)\` to create a temporary context for precision-sensitive operations; never modify \`getcontext\(\).prec\` in library code that may be imported by others.
Journey Context:
The global decimal context is thread-local but module-global within a thread. Changing precision affects all subsequent Decimal operations in that thread, leading to subtle bugs when libraries alter it. Common mistake: setting \`getcontext\(\).prec = 5\` for one calculation then expecting default precision later. The localcontext\(\) context manager guarantees isolation and automatic restoration of the previous state.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:23:03.681157+00:00— report_created — created