fix(backends): serialize timedelta values in JSON responses#1174
Draft
aiolibsbot wants to merge 1 commit into
Draft
fix(backends): serialize timedelta values in JSON responses#1174aiolibsbot wants to merge 1 commit into
aiolibsbot wants to merge 1 commit into
Conversation
sa.Interval columns yield datetime.timedelta, which the JSON Encoder did not handle — every read of a resource with an Interval column raised TypeError and returned 500. Serialize timedelta via str() to match the TextField fallthrough these columns render as. Continues the Encoder/FIELD_TYPES drift class: Decimal (aio-libs#1172), UUID (aio-libs#1173), now timedelta — the last known unhandled value type from the sqlalchemy.py TODO block.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1174 +/- ##
==========================================
+ Coverage 95.56% 95.63% +0.06%
==========================================
Files 21 21
Lines 2954 2975 +21
Branches 193 199 +6
==========================================
+ Hits 2823 2845 +22
+ Misses 105 104 -1
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 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
datetime.timedeltavalues in JSON responses so resources withsa.Intervalcolumns can be read.Why:
sa.Intervalcolumns yieldtimedelta, whichEncoder.defaultdidn't handle (it covereddate/time/Enum/bytes/Decimal/UUID). Any read of a resource with an Interval column raisedTypeErrorand returned a 500. Interval isn't inFIELD_TYPES, so it falls through to the defaultTextField/TextInput— setup succeeds, but the first read crashes.How: Added
timedeltato the existingisinstance(o, (date, time))→str(o)branch, matching the TextField the column renders as. This closes the last known unhandled value type from thesqlalchemy.pyTODO block, continuing the Encoder/FIELD_TYPES drift fixes (Decimal #1172, UUID #1173).Testing: Added
test_interval— an end-to-end read of ansa.Intervalcolumn, asserting the response serializes ("2:30:00") rather than 500ing. Full backends suite: 19 passed.Quality Report
Changes: 2 files changed, 40 insertions(+), 3 deletions(-)
Code scan: clean
Tests: failed (command not found)
Branch hygiene: clean
Generated by Kōan