fix(backends): serialize Decimal values in JSON responses#1172
Draft
aiolibsbot wants to merge 1 commit into
Draft
fix(backends): serialize Decimal values in JSON responses#1172aiolibsbot wants to merge 1 commit into
aiolibsbot wants to merge 1 commit into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jul 1, 2026
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.
What: Serialize
decimal.Decimalvalues in admin JSON responses.Why:
sa.Numeric/DECIMALcolumns returndecimal.Decimalfrom the driver.The
Encoderhandleddate/time/Enum/bytesbut notDecimal, sojson.dumpsraisedTypeError: 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
Decimalbranch toEncoder.defaultreturningfloat(o)— matchesthe
NumberField/NumberInputcomponents these columns already render as, and thevalue round-trips back through pydantic (
float→Decimal) on write. Float64 isthe 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 aNumeric(10,2)column,asserting
priceserializes as3.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