Skip to content

fix(backends): serialize UUID values in JSON responses#1173

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

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

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What: Serialize uuid.UUID values in JSON API responses.

Why: sa.Uuid columns are mapped to TextField/TextInput in FIELD_TYPES, but the value SQLAlchemy returns is a uuid.UUID object. Encoder.default in backends/abc.py handled date/time/Enum/bytes but not UUID, so json.dumps raised TypeError and every read (get_one/get_list/get_many) of a resource with a UUID column returned 500. Same class of gap as the Decimal fix (#1172); UUID was the next unhandled type.

How: One branch in Encoder.default: UUID -> str(o) (canonical form). This matches the TextField/TextInput contract and the canonical-form regex validator already emitted for UUID inputs (#1168).

Testing: Added test_uuid — an end-to-end get_one against a model with a Mapped[uuid.UUID] column, asserting 200 and the canonical string in the payload. Full suite: 99 passed, 1 xfailed.


Quality Report

Changes: 2 files changed, 43 insertions(+)

Code scan: clean

Tests: failed (command not found)

Branch hygiene: clean

Generated by Kōan

sa.Uuid columns yield uuid.UUID objects, which the JSON Encoder did not
handle — every read of a resource with a UUID column raised TypeError and
returned 500. Serialize UUID as its canonical string form, matching the
TextField/TextInput frontend contract and the UUID input regex validator.
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.66%. Comparing base (2448fd1) to head (d0fb38c).
⚠️ Report is 168 commits behind head on master.

Files with missing lines Patch % Lines
aiohttp_admin/backends/abc.py 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1173      +/-   ##
==========================================
+ Coverage   95.56%   95.66%   +0.10%     
==========================================
  Files          21       21              
  Lines        2954     2979      +25     
  Branches      193      200       +7     
==========================================
+ 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% <96.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