summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-06-01 17:27:13 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-06-01 17:27:13 +0000
commit6e8bc369d2423de7d949c242c99c97cc2cc2dea9 (patch)
treecabd37ab6d4c74992e78aefe5c4e7ac9e848b61a /test/sql
parent7b6fb299bb6b47dfeb22a5650b95af7fa0b35ec2 (diff)
parent14250f2668151f1c4df86dbf962c771e9788111e (diff)
downloadsqlalchemy-6e8bc369d2423de7d949c242c99c97cc2cc2dea9.tar.gz
Merge "propagate proxy_key from WrapsColumnExpression" into main
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compiler.py3
-rw-r--r--test/sql/test_labels.py28
2 files changed, 30 insertions, 1 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 6ad2aa2c1..94c38548f 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -3298,7 +3298,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
(exprs[1], "hoho", "hoho(mytable.myid)", "hoho_1"),
(
exprs[2],
- "_no_label",
+ "name",
"CAST(mytable.name AS NUMERIC)",
"name", # due to [ticket:4449]
),
@@ -3322,6 +3322,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
t = table1
s1 = select(col).select_from(t)
+ eq_(col._proxy_key, key if key != "_no_label" else None)
eq_(list(s1.subquery().c.keys()), [key])
if lbl:
diff --git a/test/sql/test_labels.py b/test/sql/test_labels.py
index 8c8e9dbed..d385b9e8d 100644
--- a/test/sql/test_labels.py
+++ b/test/sql/test_labels.py
@@ -26,6 +26,7 @@ from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import engines
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
+from sqlalchemy.testing import is_
from sqlalchemy.testing import mock
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -938,6 +939,33 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL):
"some_table.name FROM some_table",
)
+ @testing.combinations("inside", "outside")
+ def test_wraps_col_expr_label_propagate(self, cast_location):
+ """test #8084"""
+
+ table1 = self.table1
+
+ if cast_location == "inside":
+ expr = cast(table1.c.name, Integer).label("foo")
+ elif cast_location == "outside":
+ expr = cast(table1.c.name.label("foo"), Integer)
+ else:
+ assert False
+
+ self.assert_compile(
+ select(expr),
+ "SELECT CAST(some_table.name AS INTEGER) AS foo FROM some_table",
+ )
+ is_(select(expr).selected_columns.foo, expr)
+
+ subq = select(expr).subquery()
+ self.assert_compile(
+ select(subq).where(subq.c.foo == 10),
+ "SELECT anon_1.foo FROM (SELECT CAST(some_table.name AS INTEGER) "
+ "AS foo FROM some_table) AS anon_1 WHERE anon_1.foo = :foo_1",
+ checkparams={"foo_1": 10},
+ )
+
def test_type_coerce_auto_label_label_style_disambiguate(self):
table1 = self.table1