fix(uuid): coerce UUID values in process_literal_param - #826
Open
RitiGrover wants to merge 1 commit into
Open
RitiGrover wants to merge 1 commit into
RitiGrover wants to merge 1 commit into
Conversation
process_bind_param does the real coercion (str for native columns, hex/bytes for the CHAR/BINARY fallback), but process_literal_param was a no-op that returned the raw uuid.UUID object untouched. Any literal rendering path (literal_binds=True, Values(...), etc.) then passed an uncoerced UUID into the compiler, raising TypeError or CompileError depending on dialect. Fixes kvesteri#625
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.
Description
UUIDType.process_bind_paramdoes the real coercion (str for native UUID columns, hex/bytes for the CHAR/BINARY fallback), butprocess_literal_paramwas a no-op that returned the rawuuid.UUIDobject untouched. Any literal-rendering path (literal_binds=True,Values(..., literal_binds=True), etc.) then passed an uncoerced UUID straight into the compiler.Motivation and Context
Fixes #625. This regressed in 0.38.3. Affects the
binary=False(CHAR) fallback used on dialects without native UUID support, and any dialect used withnative=False- exactly the case in the original report (UUIDType(binary=False)).How Has This Been Tested?
test_literal_bind_non_native_fallback), confirmed it fails on the old code (CompileError: Could not render literal value "UUID(...)" with datatype CHAR(32)) and passes with the fixtests/types/suite: 1899 passed, no new failures (28 pre-existing collection errors are unrelated missing DB-driver packages in this environment)flake8clean on the changed filesOne thing I want to flag rather than silently leave out:
UUIDType()with the defaultbinary=Trueon a non-native dialect (e.g. plain MySQL) still can't be literal-rendered, because SQLAlchemy's own coreBINARYtype naively tries to UTF-8-decode arbitrary binary data for literal SQL. That's a separate, pre-existing SQLAlchemy-core limitation this change doesn't touch.