summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-12-28 12:04:07 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-12-28 12:19:03 -0500
commite68173bf7d296b2948abed06f79c7cbd0ab66b0d (patch)
tree33ac8c8b5155660d289ddc842670340a3895048a /test/sql
parent8e041e24182c8f4b7762ebbecd494f7dbf86b818 (diff)
downloadsqlalchemy-e68173bf7d296b2948abed06f79c7cbd0ab66b0d.tar.gz
ensure whereclause, returning copied as tuples
Fixed issue in the internal SQL traversal for DML statements like :class:`_dml.Update` and :class:`_dml.Delete` which would cause among other potential issues, a specific issue using lambda statements with the ORM update/delete feature. Fixes: #9033 Change-Id: I76428049cb767ba302fbea89555114bf63ab8687
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_external_traversal.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/sql/test_external_traversal.py b/test/sql/test_external_traversal.py
index 8940276e3..8ccbd8d20 100644
--- a/test/sql/test_external_traversal.py
+++ b/test/sql/test_external_traversal.py
@@ -2964,3 +2964,41 @@ class ValuesBaseTest(fixtures.TestBase, AssertsCompiledSQL):
"UPDATE construct does not support multiple parameter sets.",
stmt.compile,
)
+
+ @testing.variation("stmt_type", ["update", "delete"])
+ def test_whereclause_returning_adapted(self, stmt_type):
+ """test #9033"""
+
+ if stmt_type.update:
+ stmt = (
+ t1.update()
+ .where(t1.c.col1 == 10)
+ .values(col1=15)
+ .returning(t1.c.col1)
+ )
+ elif stmt_type.delete:
+ stmt = t1.delete().where(t1.c.col1 == 10).returning(t1.c.col1)
+ else:
+ stmt_type.fail()
+
+ stmt = visitors.replacement_traverse(stmt, {}, lambda elem: None)
+
+ assert isinstance(stmt._where_criteria, tuple)
+ assert isinstance(stmt._returning, tuple)
+
+ stmt = stmt.where(t1.c.col2 == 5).returning(t1.c.col2)
+
+ if stmt_type.update:
+ self.assert_compile(
+ stmt,
+ "UPDATE table1 SET col1=:col1 WHERE table1.col1 = :col1_1 "
+ "AND table1.col2 = :col2_1 RETURNING table1.col1, table1.col2",
+ )
+ elif stmt_type.delete:
+ self.assert_compile(
+ stmt,
+ "DELETE FROM table1 WHERE table1.col1 = :col1_1 "
+ "AND table1.col2 = :col2_1 RETURNING table1.col1, table1.col2",
+ )
+ else:
+ stmt_type.fail()