summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorEric Masseran <eric.masseran@gmail.com>2021-08-06 04:11:09 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-08-08 10:44:14 -0400
commit770d50092f847ef7e79a895c72a680f7626a1164 (patch)
tree29ad4d469307d26ee8caf9baed25d4522aaff99e /lib/sqlalchemy/sql/compiler.py
parentb75630cec9418ef087e7c6af0370ac6ba728a251 (diff)
downloadsqlalchemy-770d50092f847ef7e79a895c72a680f7626a1164.tar.gz
Dispatch independent ctes on compound select
Fix issue in :class:`_sql.CTE` where new :meth:`_sql.HasCTE.add_cte` method added in version 1.4.21 / :ticket:`6752` failed to function correctly for "compound select" structures such as :func:`_sql.union`, :func:`_sql.union_all`, :func:`_sql.except`, etc. Pull request courtesy Eric Masseran. Fixes: #6752 Closes: #6849 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6849 Pull-request-sha: 1c4b4d72b2789cf89ff5043ca964ebdd6c9a6617 Change-Id: I49a16a4fc2af8299502011f3a02d8a2ad93255e3
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index a81507acb..1e090ef10 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -1787,6 +1787,8 @@ class SQLCompiler(Compiled):
if toplevel and not self.compile_state:
self.compile_state = compile_state
+ compound_stmt = compile_state.statement
+
entry = self._default_stack_entry if toplevel else self.stack[-1]
need_result_map = toplevel or (
not compound_index
@@ -1807,6 +1809,10 @@ class SQLCompiler(Compiled):
}
)
+ if compound_stmt._independent_ctes:
+ for cte in compound_stmt._independent_ctes:
+ cte._compiler_dispatch(self, **kwargs)
+
keyword = self.compound_keywords.get(cs.keyword)
text = (" " + keyword + " ").join(