feat(json): emit Decimals as exact number literals (frontend-decimal epic, step A)#215
Merged
Conversation
…epic, step A) The JSON provider serialized every Decimal via float() (core/charts.py), so monetary values crossed the wire as lossy float64 — visible to raw API consumers, exports, and high-precision values, and it leaked custom/budget amounts as float (R8). Switch dumps to simplejson with use_decimal=True: Decimals now emit as exact number literals (100.00, 88.571428571428571428571428571, ...). This is: - exact on the wire — a decimal-aware consumer recovers the exact value; - R8 fixed — custom amount values are exact, matching Balance/Price; - transparent to the frontend — the literals are valid JSON numbers, so JSON.parse still reads them (as float64 for display); no frontend change and no snapshot churn (the snapshot fixture re-parses to float before comparing). loads stays stdlib json (request parsing unaffected). The residual float64 narrowing on a plain-JSON.parse read is the frontend-decimal step (step B), tracked separately. Adds simplejson as a core dep + types-simplejson stub. test_number_precision_boundary rewritten: every value now crosses the wire exactly (the old high-precision xfail flips), with a test documenting the remaining float-parse narrowing on the read side.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step A of the frontend-decimal epic — closes the wire half of C2 and fixes R8, and it landed far smaller than the original "regenerate 53 snapshots" estimate.
What
The JSON provider serialized every
Decimalviafloat()(core/charts.py), so monetary values crossed the wire as lossy float64. Switchdumpstosimplejsonwithuse_decimal=True→ Decimals emit as exact number literals (88.571428571428571428571428571instead of88.57142857142857).float()intermediate is gone.JSON.parsestill reads them (float64 for display, same as today). No frontend change, no snapshot churn (the snapshot fixture re-parses to float before comparing).Scope & verification
Diff is 3 files (
charts.py,pyproject.toml,uv.lock) + the boundary test. Full py suite 100% coverage, 544 passed; JS 86 pass;just mypyclean.test_number_precision_boundaryrewritten: every value now crosses the wire exactly (the old high-precisionxfailflips to passing), with one test documenting the residual — a plainJSON.parse/json.loadsread still narrows to float64.To weigh
simplejson(+types-simplejsonstub). It's the clean way to emit exact Decimal literals (stdlibjsoncan't — its C encoder ignores a float subclass's__repr__).loadsstays stdlibjson, so request parsing is unaffected.🤖 Generated with Claude Code