Fix UUID handling in OData queries#60
Open
AHMETCEMRE wants to merge 1 commit into
Open
Conversation
Author
|
Hi @OliverHofkens, Again, thank you for this great project! It's been very useful for our work, but this uuid issue is quite important for us to resolve. Could you kindly review the PR at your earliest convenience? |
|
Thanks @OliverHofkens and @AHMETCEMRE , this is a great fix! |
|
Looks great, can this me merged and released? |
MrToCode
added a commit
to MrToCode/odata-query
that referenced
this pull request
Feb 18, 2026
…lla-co#60 selective) Updates the GUID lexer rule to strip optional surrounding quotes, and updates visit_GUID() to emit a properly-typed UUID literal on SQLAlchemy 2.0+ (via sqlalchemy.types.Uuid). On SQLAlchemy <2.0, falls back to a string literal to maintain backwards compatibility with the 1.4 series. No poetry.lock or pyproject.toml changes included. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
MrToCode
added a commit
to MrToCode/odata-query
that referenced
this pull request
Feb 18, 2026
[TC intake] upstream gorilla-co#60 uuid handling — preserve UUID typing in GUID literals with SQLAlchemy 2.x compat
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.
Pull Request Description
This pull request addresses the issue of UUID handling in
odata-querywith SQLAlchemy, ensuring that UUIDs are treated correctly in query filters, which was previously causing errors. My solution is particularly relevant to the ongoing discussion in Issue #25 ("Filter not working for uuid column") raised by schwingkopf and others, where similar issues were encountered when filtering on UUID columns.Problem Statement:
In my case, I encountered an issue where filtering by UUID columns in a PostgreSQL database resulted in the following error:
This occurred because
odata-querywas generating SQL queries that incorrectly treated UUIDs asVARCHARtypes, leading to invalid SQL statements. The error message highlighted that theUUIDtype was being compared with aVARCHAR, which is not allowed.This issue mirrors the one reported in Issue #25, where filtering by UUID columns produced no results due to a similar type mismatch.
Changes Made:
grammar.pyChanges:_UUID_PATTERN) to properly recognize UUIDs with or without quotes.GUIDmethod to remove unnecessary quotes and parse UUIDs asGUIDobjects:This change ensures that UUIDs are treated correctly in the query parsing phase.
common.pyChanges:visit_GUIDmethod to ensure UUIDs are passed asUUIDobjects in SQLAlchemy queries instead ofVARCHARstrings:This is essential to prevent the type mismatch that was causing the errors. As mentioned in Issue Filter not working for uuid column #25, SQLAlchemy expects UUIDs to be handled in a specific way, and this change resolves the mismatch by ensuring that the UUID remains in its proper form throughout query generation.
Test Changes:
Updated tests in both
test_odata_to_sqlalchemy_core.pyandtest_odata_to_sqlalchemy_orm.py:Updated UUID comparisons to use
UUIDobjects:Updated
INclause tests:These changes ensure that the UUIDs are passed in their correct type during tests, which prevents the type mismatch errors that were mentioned in Issue Filter not working for uuid column #25 when handling UUIDs in
INclauses.Contribution to the Discussion:
This pull request contributes directly to the ongoing conversation in Issue #25, where both I and other users faced similar UUID-related problems. The problem, as described in the issue, revolves around handling UUIDs properly in queries, particularly ensuring they are treated as UUID types instead of strings or VARCHARs.
In my solution, I upgraded SQLAlchemy to version ^2.0, which offers better support for UUIDs. I have tested my changes with both PostgreSQL and SQLite databases, and in both cases, I was able to successfully filter records using UUID values.
Thank you for providing such a useful library, and I hope this PR helps to resolve the issue or at least opens further discussion on UUID handling.