Skip to content

fix(backends): serialize timedelta values in JSON responses#1174

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

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

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What: Serialize datetime.timedelta values in JSON responses so resources with sa.Interval columns can be read.

Why: sa.Interval columns yield timedelta, which Encoder.default didn't handle (it covered date/time/Enum/bytes/Decimal/UUID). Any read of a resource with an Interval column raised TypeError and returned a 500. Interval isn't in FIELD_TYPES, so it falls through to the default TextField/TextInput — setup succeeds, but the first read crashes.

How: Added timedelta to the existing isinstance(o, (date, time))str(o) branch, matching the TextField the column renders as. This closes the last known unhandled value type from the sqlalchemy.py TODO block, continuing the Encoder/FIELD_TYPES drift fixes (Decimal #1172, UUID #1173).

Testing: Added test_interval — an end-to-end read of an sa.Interval column, 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

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

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.63%. Comparing base (2448fd1) to head (93d037b).
⚠️ Report is 168 commits behind head on master.

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              
Flag Coverage Δ
integration 81.22% <100.00%> (+0.27%) ⬆️
js 83.89% <ø> (ø)
unit 97.48% <100.00%> (+0.06%) ⬆️

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