From a0953bb7095dde805de8c13699b122767ed001b9 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 3 Jul 2021 19:48:55 -0400 Subject: Adjust CTE recrusive col list to accommodate dupe col names Fixed issue in CTE constructs where a recursive CTE that referred to a SELECT that has duplicate column names, which are typically deduplicated using labeling logic in 1.4, would fail to refer to the deduplicated label name correctly within the WITH clause. As part of this change we are also attempting to remove the behavior of SelectStatementGrouping forcing off the "asfrom" contextual flag, which will have the result of additional labeling being applied to some UNION and similar statements when they are interpreted as subqueries. To maintain compatibility with "grouping", the Grouping/SelectStatementGrouping are now broken out into two separate compiler cases, as the "asfrom" logic appears to be tailored towards table valued SELECTS as column expressions. Fixes: #6710 Change-Id: I8af07a5c670dbe5736cd9f16084ef82f5e4c8642 --- lib/sqlalchemy/sql/selectable.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/selectable.py') diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 30a613089..b6cf7f55e 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -3139,7 +3139,7 @@ class SelectStatementGrouping(GroupedElement, SelectBase): """ - __visit_name__ = "grouping" + __visit_name__ = "select_statement_grouping" _traverse_internals = [("element", InternalTraversal.dp_clauseelement)] _is_select_container = True @@ -3173,6 +3173,9 @@ class SelectStatementGrouping(GroupedElement, SelectBase): def self_group(self, against=None): return self + def _generate_columns_plus_names(self, anon_for_dupe_key): + return self.element._generate_columns_plus_names(anon_for_dupe_key) + def _generate_fromclause_column_proxies(self, subquery): self.element._generate_fromclause_column_proxies(subquery) -- cgit v1.2.1