Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2772b57

Browse filesBrowse files
authored
fix: iexact lookup with Transform expression crash issue when RHS is direct value and a transform function is involved (#628)
* fix: lint_setup_py was failing in Kokoro is not fixed * fix: iexact lookup with Transform expression chash issue #612
1 parent 3a8d922 commit 2772b57
Copy full SHA for 2772b57

File tree

2 files changed

+18
-1
lines changed
Filter options

2 files changed

+18
-1
lines changed

‎django_spanner/lookups.py

Copy file name to clipboardExpand all lines: django_spanner/lookups.py
+4-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ def iexact(self, compiler, connection):
100100
# lhs_sql is the expression/column to use as the regular expression.
101101
# Use concat to make the value case-insensitive.
102102
lhs_sql = "CONCAT('^(?i)', " + lhs_sql + ", '$')"
103-
rhs_sql = rhs_sql.replace("%%s", "%s")
103+
if not self.rhs_is_direct_value() and not params:
104+
# If rhs is not a direct value and parameter is not present we want
105+
# to have only 1 formatable argument in rhs_sql else we need 2.
106+
rhs_sql = rhs_sql.replace("%%s", "%s")
104107
# rhs_sql is REGEXP_CONTAINS(%s, %%s), and lhs_sql is the column name.
105108
return rhs_sql % lhs_sql, params
106109

‎tests/unit/django_spanner/test_lookups.py

Copy file name to clipboardExpand all lines: tests/unit/django_spanner/test_lookups.py
+14
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,17 @@ def test_iexact_sql_query_case_insensitive_function_transform(self):
283283
+ "CONCAT('^(?i)', CAST(UPPER(tests_author.name) AS STRING), '$'))",
284284
)
285285
self.assertEqual(params, ())
286+
287+
def test_iexact_sql_query_case_insensitive_value_match(self):
288+
289+
qs1 = Author.objects.filter(name__upper__iexact="abc").values("name")
290+
compiler = SQLCompiler(qs1.query, self.connection, "default")
291+
sql_compiled, params = compiler.as_sql()
292+
293+
self.assertEqual(
294+
sql_compiled,
295+
"SELECT tests_author.name FROM tests_author WHERE "
296+
+ "REGEXP_CONTAINS((UPPER(CONCAT('^(?i)', "
297+
+ "CAST(UPPER(tests_author.name) AS STRING), '$'))), %s)",
298+
)
299+
self.assertEqual(params, ("abc",))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.