summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/crud.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-09-16 13:38:11 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-09-16 13:40:47 -0400
commit8fca5b6e6a42b6221faaf26a912603393afd8607 (patch)
treed06793fc78d9835b040bf2a9d14b35e3da46162a /lib/sqlalchemy/sql/crud.py
parentc27bf6f7ecc1a120f0c8029eaa5969b6d2aa255d (diff)
downloadsqlalchemy-8fca5b6e6a42b6221faaf26a912603393afd8607.tar.gz
use the stack for insert_from_select
Fixed issue related to new ``add_cte()`` feature where pairing two "INSERT..FROM SELECT" statements simultaneously would lose track of the two independent SELECT statements, leading to the wrong SQL. Fixes: #7036 Change-Id: I90fe47eb203bc5c1ea5810db0edba08250b2b7e6
Diffstat (limited to 'lib/sqlalchemy/sql/crud.py')
-rw-r--r--lib/sqlalchemy/sql/crud.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py
index b8f8cb4ce..d43f33ebb 100644
--- a/lib/sqlalchemy/sql/crud.py
+++ b/lib/sqlalchemy/sql/crud.py
@@ -310,7 +310,9 @@ def _scan_insert_from_select_cols(
cols = [stmt.table.c[_column_as_key(name)] for name in stmt._select_names]
- compiler._insert_from_select = stmt.select
+ assert compiler.stack[-1]["selectable"] is stmt
+
+ compiler.stack[-1]["insert_from_select"] = stmt.select
add_select_cols = []
if stmt.include_insert_from_select_defaults:
@@ -331,10 +333,12 @@ def _scan_insert_from_select_cols(
if add_select_cols:
values.extend(add_select_cols)
- compiler._insert_from_select = compiler._insert_from_select._generate()
- compiler._insert_from_select._raw_columns = tuple(
- compiler._insert_from_select._raw_columns
+ ins_from_select = compiler.stack[-1]["insert_from_select"]
+ ins_from_select = ins_from_select._generate()
+ ins_from_select._raw_columns = tuple(
+ ins_from_select._raw_columns
) + tuple(expr for col, col_expr, expr in add_select_cols)
+ compiler.stack[-1]["insert_from_select"] = ins_from_select
def _scan_cols(