summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-12-15 10:22:36 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-12-15 10:34:05 -0500
commit84ba8874e146bcdbf46ce70ece32c4c224c3fd44 (patch)
tree668b79268cc172ad4292a1875b3d9d14c8eaf47e /test/sql
parent6f6dc443663f6b63a8fe48b3504cae59cfbe9d56 (diff)
downloadsqlalchemy-84ba8874e146bcdbf46ce70ece32c4c224c3fd44.tar.gz
implement literal_binds with expanding + bind_expression
Fixed bug where SQL compilation would fail (assertion fail in 2.0, NoneType error in 1.4) when using an expression whose type included :meth:`_types.TypeEngine.bind_expression`, in the context of an "expanding" (i.e. "IN") parameter in conjunction with the ``literal_binds`` compiler parameter. Fixes: #8989 Change-Id: Ic9fd27b46381b488117295ea5a492d8fc158e39f (cherry picked from commit 8c6de3c2c43ab372cbbe76464b4c5be3b6457252)
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_type_expressions.py48
1 files changed, 30 insertions, 18 deletions
diff --git a/test/sql/test_type_expressions.py b/test/sql/test_type_expressions.py
index e0e0858a4..7c2192620 100644
--- a/test/sql/test_type_expressions.py
+++ b/test/sql/test_type_expressions.py
@@ -182,28 +182,40 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL):
"test_table WHERE test_table.y = lower(:y_1)",
)
- def test_in_binds(self):
+ @testing.variation(
+ "compile_opt", ["plain", "postcompile", "literal_binds"]
+ )
+ def test_in_binds(self, compile_opt):
table = self._fixture()
- self.assert_compile(
- select(table).where(
- table.c.y.in_(["hi", "there", "some", "expr"])
- ),
- "SELECT test_table.x, lower(test_table.y) AS y FROM "
- "test_table WHERE test_table.y IN "
- "(__[POSTCOMPILE_y_1~~lower(~~REPL~~)~~])",
- render_postcompile=False,
+ stmt = select(table).where(
+ table.c.y.in_(["hi", "there", "some", "expr"])
)
- self.assert_compile(
- select(table).where(
- table.c.y.in_(["hi", "there", "some", "expr"])
- ),
- "SELECT test_table.x, lower(test_table.y) AS y FROM "
- "test_table WHERE test_table.y IN "
- "(lower(:y_1_1), lower(:y_1_2), lower(:y_1_3), lower(:y_1_4))",
- render_postcompile=True,
- )
+ if compile_opt.plain:
+ self.assert_compile(
+ stmt,
+ "SELECT test_table.x, lower(test_table.y) AS y FROM "
+ "test_table WHERE test_table.y IN "
+ "(__[POSTCOMPILE_y_1~~lower(~~REPL~~)~~])",
+ render_postcompile=False,
+ )
+ elif compile_opt.postcompile:
+ self.assert_compile(
+ stmt,
+ "SELECT test_table.x, lower(test_table.y) AS y FROM "
+ "test_table WHERE test_table.y IN "
+ "(lower(:y_1_1), lower(:y_1_2), lower(:y_1_3), lower(:y_1_4))",
+ render_postcompile=True,
+ )
+ elif compile_opt.literal_binds:
+ self.assert_compile(
+ stmt,
+ "SELECT test_table.x, lower(test_table.y) AS y FROM "
+ "test_table WHERE test_table.y IN "
+ "(lower('hi'), lower('there'), lower('some'), lower('expr'))",
+ literal_binds=True,
+ )
def test_dialect(self):
table = self._fixture()