diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-18 19:34:32 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-18 21:47:46 -0400 |
| commit | c1c999c01d595b74fe178d9bdbff34fd8939a283 (patch) | |
| tree | 7b6c7d0395096c29b43fcbbe6c4c5f8a7138daf8 /test/sql | |
| parent | d0812a1abf903f6b5f1a0bfb19f8c87a665f8309 (diff) | |
| download | sqlalchemy-c1c999c01d595b74fe178d9bdbff34fd8939a283.tar.gz | |
Ensure ClauseAdapter treats FunctionElement as a ColumnElement
Fixed regression where use of an unnamed SQL expression such as a SQL
function would raise a column targeting error if the query itself were
using joinedload for an entity and was also being wrapped in a subquery by
the joinedload eager loading process.
Fixes: #6086
Change-Id: I22cf4d6974685267c4f903bd7639be8271c6c1ef
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_external_traversal.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/sql/test_external_traversal.py b/test/sql/test_external_traversal.py index bc6013791..b7e58dad9 100644 --- a/test/sql/test_external_traversal.py +++ b/test/sql/test_external_traversal.py @@ -1338,6 +1338,40 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "AS anon_1 FROM table1 AS t1alias", ) + def test_adapt_select_w_unlabeled_fn(self): + + expr = func.count(t1.c.col1) + stmt = select(t1, expr) + + self.assert_compile( + stmt, + "SELECT table1.col1, table1.col2, table1.col3, " + "count(table1.col1) AS count_1 FROM table1", + ) + + stmt2 = select(stmt.subquery()) + + self.assert_compile( + stmt2, + "SELECT anon_1.col1, anon_1.col2, anon_1.col3, anon_1.count_1 " + "FROM (SELECT table1.col1 AS col1, table1.col2 AS col2, " + "table1.col3 AS col3, count(table1.col1) AS count_1 " + "FROM table1) AS anon_1", + ) + + is_( + stmt2.selected_columns[3], + stmt2.selected_columns.corresponding_column(expr), + ) + + is_( + sql_util.ClauseAdapter(stmt2).replace(expr), + stmt2.selected_columns[3], + ) + + column_adapter = sql_util.ColumnAdapter(stmt2) + is_(column_adapter.columns[expr], stmt2.selected_columns[3]) + def test_correlate_except_on_clone(self): # test [ticket:4537]'s issue |
