summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-01-18 17:19:24 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-01-18 17:19:24 -0500
commite28ec27b599558b3e26ced106a972e8b4aa9e668 (patch)
treec89c5447fd7ba8ace3c334918e0d43e34d44c851 /test/sql
parente6ded82eef63235d7cbfe3ab3382a48f32913640 (diff)
downloadsqlalchemy-e28ec27b599558b3e26ced106a972e8b4aa9e668.tar.gz
reject methods as lambda SQL callables
Added an informative error message when a method object is passed to a SQL construct. Previously, when such a callable were passed, as is a common typographical error when dealing with method-chained SQL constructs, they were interpreted as "lambda SQL" targets to be invoked at compilation time, which would lead to silent failures. As this feature was not intended to be used with methods, method objects are now rejected. Fixes: #7032 Change-Id: If714715bd8c11557ab769ee3b1a24264b0b06acc
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_lambdas.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/sql/test_lambdas.py b/test/sql/test_lambdas.py
index 43aed0672..96a6ecbf4 100644
--- a/test/sql/test_lambdas.py
+++ b/test/sql/test_lambdas.py
@@ -8,6 +8,7 @@ from sqlalchemy.sql import and_
from sqlalchemy.sql import bindparam
from sqlalchemy.sql import coercions
from sqlalchemy.sql import column
+from sqlalchemy.sql import func
from sqlalchemy.sql import join
from sqlalchemy.sql import lambda_stmt
from sqlalchemy.sql import lambdas
@@ -38,6 +39,26 @@ class LambdaElementTest(
):
__dialect__ = "default"
+ def test_reject_methods(self):
+ """test #7032"""
+
+ t1 = table("t1", column("q"), column("p"))
+
+ subq = select(t1).subquery
+
+ with expect_raises_message(
+ exc.ArgumentError,
+ "Method <bound method SelectBase.subquery .* may not be "
+ "passed as a SQL expression",
+ ):
+ select(func.count()).select_from(subq)
+
+ self.assert_compile(
+ select(func.count()).select_from(subq()),
+ "SELECT count(*) AS count_1 FROM "
+ "(SELECT t1.q AS q, t1.p AS p FROM t1) AS anon_1",
+ )
+
def test_select_whereclause(self):
t1 = table("t1", column("q"), column("p"))