fix: handle uuid.UUID conversion in query params#1643
Open
toroleapinc wants to merge 2 commits intoaio-libs:masterfrom
Open
fix: handle uuid.UUID conversion in query params#1643toroleapinc wants to merge 2 commits intoaio-libs:masterfrom
toroleapinc wants to merge 2 commits intoaio-libs:masterfrom
Conversation
- Added explicit UUID handling to query_var function
- UUID objects now convert to string representation instead of integer
- Added comprehensive tests for UUID in query parameters
- Updated type hints to include uuid.UUID in SimpleQuery type
- Fixes issue where UUID('3199712f-1b78-4420-852b-a73ee09e6a8f')
would become '65928888857327045292976149998723820175' instead
of '3199712f-1b78-4420-852b-a73ee09e6a8f'
Closes aio-libs#1458
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (97.64%) is below the target coverage (100.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #1643 +/- ##
=======================================
Coverage 99.47% 99.48%
=======================================
Files 30 30
Lines 5942 5977 +35
Branches 283 284 +1
=======================================
+ Hits 5911 5946 +35
Misses 22 22
Partials 9 9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
naarob
pushed a commit
to naarob/yarl
that referenced
this pull request
Mar 26, 2026
…ry (aio-libs#1643), split_url delim perf fix aio-libs#1630: URL.__repr__ exposed passwords in plaintext, risking credential leakage in logs and tracebacks. Added password masking with '********'. str(), == and all other operations remain unaffected. fix aio-libs#1643: uuid.UUID was converted to int in query params because UUID implements __int__(), matching the SupportsInt protocol. Fixed by checking whether type(v).__str__ is not object.__str__ before using int() conversion. This is a general solution that works for any type with a meaningful __str__. perf: split_url() delimiter search refactored from a for-loop over delim_chars to 3 conditional find() calls using the already-computed has_hash and has_question_mark flags. Reduces per-call overhead for URL-heavy workloads.
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.
This PR fixes the issue where uuid.UUID objects were being converted to integers instead of their string representation when used as query parameter values.
Problem
When passing a uuid.UUID object as a query parameter, yarl was converting it to an integer because UUID implements int(), making it match the SupportsInt protocol. This resulted in URLs like:
Expected: http://example.com?user_id=3199712f-1b78-4420-852b-a73ee09e6a8f
Actual: http://example.com?user_id=65928888857327045292976149998723820175
Solution
Added explicit handling for uuid.UUID objects in the query_var function to prioritize string conversion over integer conversion. The fix:
Changes
Testing
Added test cases covering:
Fixes #1458