fix(backends): serialize UUID values in JSON responses#1173
Draft
aiolibsbot wants to merge 1 commit into
Draft
Conversation
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 Report❌ Patch coverage is
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
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
uuid.UUIDvalues in JSON API responses.Why:
sa.Uuidcolumns are mapped toTextField/TextInputinFIELD_TYPES, but the value SQLAlchemy returns is auuid.UUIDobject.Encoder.defaultinbackends/abc.pyhandleddate/time/Enum/bytesbut notUUID, sojson.dumpsraisedTypeErrorand 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 theTextField/TextInputcontract 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 aMapped[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