summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-08-22 18:55:59 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-08-22 18:55:59 -0400
commit16d66d35644eaa6609fdc5c8f805314f7cf4d0fc (patch)
tree563b1f9de236bf20918202fbb0cab813494ba3e9 /lib/sqlalchemy/sql/compiler.py
parent8f5a31441aed9d223e67d211472445e574fc521f (diff)
downloadsqlalchemy-16d66d35644eaa6609fdc5c8f805314f7cf4d0fc.tar.gz
- [bug] Fixed bug whereby usage of a UNION
or similar inside of an embedded subquery would interfere with result-column targeting, in the case that a result-column had the same ultimate name as a name inside the embedded UNION. [ticket:2552]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index ee96c8c81..81aa62c25 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -574,9 +574,10 @@ class SQLCompiler(engine.Compiled):
return func.clause_expr._compiler_dispatch(self, **kwargs)
def visit_compound_select(self, cs, asfrom=False,
- parens=True, compound_index=1, **kwargs):
+ parens=True, compound_index=0, **kwargs):
entry = self.stack and self.stack[-1] or {}
- self.stack.append({'from':entry.get('from', None), 'iswrapper':True})
+ self.stack.append({'from': entry.get('from', None),
+ 'iswrapper': not entry})
keyword = self.compound_keywords.get(cs.keyword)
@@ -597,7 +598,7 @@ class SQLCompiler(engine.Compiled):
self.limit_clause(cs) or ""
if self.ctes and \
- compound_index == 1 and not entry:
+ compound_index == 0 and not entry:
text = self._render_cte_clause() + text
self.stack.pop(-1)
@@ -1017,7 +1018,7 @@ class SQLCompiler(engine.Compiled):
def visit_select(self, select, asfrom=False, parens=True,
iswrapper=False, fromhints=None,
- compound_index=1,
+ compound_index=0,
positional_names=None, **kwargs):
entry = self.stack and self.stack[-1] or {}
@@ -1033,11 +1034,14 @@ class SQLCompiler(engine.Compiled):
# to outermost if existingfroms: correlate_froms =
# correlate_froms.union(existingfroms)
+ populate_result_map = compound_index == 0 and (
+ not entry or \
+ entry.get('iswrapper', False)
+ )
+
self.stack.append({'from': correlate_froms,
'iswrapper': iswrapper})
- populate_result_map = compound_index == 1 and not entry or \
- entry.get('iswrapper', False)
column_clause_args = {'positional_names': positional_names}
# the actual list of columns to print in the SELECT column list.
@@ -1112,7 +1116,7 @@ class SQLCompiler(engine.Compiled):
text += self.for_update_clause(select)
if self.ctes and \
- compound_index == 1 and not entry:
+ compound_index == 0 and not entry:
text = self._render_cte_clause() + text
self.stack.pop(-1)