Repository navigation
Conversation
Previously, Django text lookups such as iexact, contains, icontains, startswith, istartswith, endswith, and iendswith were translated into Spanner regular expression checks (REGEXP_CONTAINS). When matching against expressions, column references, UUID fields, or transformed values, those values were not regex-escaped—causing characters like `.*` or `[` to act as regular expression operators or fail with invalid regex errors. For iexact queries on expressions, it also mistakenly treated the left-hand column as the regex pattern. Switch these lookups to native literal string operations in Spanner SQL: - Case-folded equality using UPPER(...) for iexact - STRPOS(...) > 0 for contains and icontains - STARTS_WITH(...) and ENDS_WITH(...) for startswith, istartswith, endswith, and iendswith Because these functions compare text literally rather than as regular expressions, metacharacters, newlines, and non-string scalar values behave consistently across literal values, expressions, subqueries, transforms, and check constraints, while regex and iregex lookups continue to evaluate regular expressions.
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors Django Spanner's pattern and case-insensitive lookups (such as iexact, contains, startswith, and endswith) to use literal Spanner string functions like STRPOS, STARTS_WITH, ENDS_WITH, UPPER, and CAST instead of regular expressions (REGEXP_CONTAINS). This ensures that regex metacharacters are treated literally. Additionally, prep_for_like_query and prep_for_iexact_query have been updated to return values unmodified, and comprehensive tests have been added to verify the new behavior. No review comments were provided, and the implementation is clean and well-tested.
This branch has not been deployed
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.
Previously, Django text lookups such as iexact, contains, icontains, startswith, istartswith, endswith, and iendswith were translated into Spanner regular expression checks (REGEXP_CONTAINS). When matching against expressions, column references, UUID fields, or transformed values, those values were not regex-escaped—causing characters like
.*or[to act as regular expression operators or fail with invalid regex errors. For iexact queries on expressions, it also mistakenly treated the left-hand column as the regex pattern.Switch these lookups to native literal string operations in Spanner SQL:
Because these functions compare text literally rather than as regular expressions, metacharacters, newlines, and non-string scalar values behave consistently across literal values, expressions, subqueries, transforms, and check constraints, while regex and iregex lookups continue to evaluate regular expressions.