Skip to content

fix(backends): serialize Decimal values in JSON responses#1172

Draft
aiolibsbot wants to merge 1 commit into
aio-libs:masterfrom
aiolibsbot:koan/fix-decimal-json-serialization
Draft

fix(backends): serialize Decimal values in JSON responses#1172
aiolibsbot wants to merge 1 commit into
aio-libs:masterfrom
aiolibsbot:koan/fix-decimal-json-serialization

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What: Serialize decimal.Decimal values in admin JSON responses.

Why: sa.Numeric/DECIMAL columns return decimal.Decimal from the driver.
The Encoder handled date/time/Enum/bytes but not Decimal, so
json.dumps raised TypeError: Object of type Decimal is not JSON serializable.
Any resource exposing a numeric column 500'd on every get_one/get_list.
No test covered a Numeric column, so it went unnoticed.

How: Add a Decimal branch to Encoder.default returning float(o) — matches
the NumberField/NumberInput components these columns already render as, and the
value round-trips back through pydantic (floatDecimal) on write. Float64 is
the frontend's native numeric type, so no precision is lost that JS wouldn't lose anyway.

Testing: Added test_numeric (end-to-end read of a Numeric(10,2) column,
asserting price serializes as 3.14). Full suite: 99 passed, 1 xfailed (pre-existing #934).


Quality Report

Changes: 2 files changed, 41 insertions(+)

Code scan: clean

Tests: failed (command not found)

Branch hygiene: clean

Generated by Kōan

sa.Numeric/DECIMAL columns yield decimal.Decimal, which the JSON Encoder
did not handle — every read of a resource with a numeric column raised
TypeError and returned 500. Serialize Decimal as float to match the
NumberField/NumberInput frontend contract.
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.66%. Comparing base (2448fd1) to head (0ff214b).
⚠️ Report is 168 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1172      +/-   ##
==========================================
+ Coverage   95.56%   95.66%   +0.10%     
==========================================
  Files          21       21              
  Lines        2954     2979      +25     
  Branches      193      201       +8     
==========================================
+ Hits         2823     2850      +27     
+ Misses        105      103       -2     
  Partials       26       26              
Flag Coverage Δ
integration 80.92% <33.33%> (-0.03%) ⬇️
js 83.89% <ø> (ø)
unit 97.52% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant