diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-12-16 16:38:06 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-12-16 16:38:06 -0500 |
commit | e7c78be2e737591d637b6acde6117893fd29dfe0 (patch) | |
tree | 11abdbd136f0e9cfcf8959a7c41d2d4d0f27772c /lib/sqlalchemy/sql/compiler.py | |
parent | 835bdabd05c83e3add3e876a861aa74105d34397 (diff) | |
download | sqlalchemy-e7c78be2e737591d637b6acde6117893fd29dfe0.tar.gz |
Do the CompoundSelect check for number of columns in the compile phase
Starting to go forward with the general idea of moving more
of Core / ORM construction into the compile phase. Bigger
initiatives like the refactor of Query will follow onto this.
Change-Id: I0f364d3182e21e32ed85ef34cfd11fd9d11cf653
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index a28ce465a..4ec3b93ea 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2149,7 +2149,9 @@ class SQLCompiler(Compiled): if not populate_result_map and "add_to_result_map" in kwargs: del kwargs["add_to_result_map"] - froms = self._setup_select_stack(select, entry, asfrom, lateral) + froms = self._setup_select_stack( + select, entry, asfrom, lateral, compound_index + ) column_clause_args = kwargs.copy() column_clause_args.update( @@ -2254,10 +2256,33 @@ class SQLCompiler(Compiled): hint_text = self.get_select_hint_text(byfrom) return hint_text, byfrom - def _setup_select_stack(self, select, entry, asfrom, lateral): + def _setup_select_stack( + self, select, entry, asfrom, lateral, compound_index + ): correlate_froms = entry["correlate_froms"] asfrom_froms = entry["asfrom_froms"] + if compound_index > 0: + # note this is cached + select_0 = entry["selectable"].selects[0] + if select_0._is_select_container: + select_0 = select_0.element + numcols = len(select_0.selected_columns) + # numcols = len(select_0._columns_plus_names) + if len(select._columns_plus_names) != numcols: + raise exc.CompileError( + "All selectables passed to " + "CompoundSelect must have identical numbers of " + "columns; select #%d has %d columns, select " + "#%d has %d" + % ( + 1, + numcols, + compound_index + 1, + len(select.selected_columns), + ) + ) + if asfrom and not lateral: froms = select._get_display_froms( explicit_correlate_froms=correlate_froms.difference( |