From 7fe400f54632835695f7b98f0c1a54424953dfad Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 3 Mar 2020 17:22:30 -0500 Subject: Restore crud flags if visiting_cte is set Fixed bug where a CTE of an INSERT/UPDATE/DELETE that also uses RETURNING could then not be SELECTed from directly, as the internal state of the compiler would try to treat the outer SELECT as a DELETE statement itself and access nonexistent state. Fixes: #5181 Change-Id: Icba76f2148c8344baa1c04bac4ab6c6d24f23072 --- lib/sqlalchemy/sql/crud.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/crud.py') diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py index 433a5fdfa..e474952ce 100644 --- a/lib/sqlalchemy/sql/crud.py +++ b/lib/sqlalchemy/sql/crud.py @@ -44,8 +44,10 @@ def _setup_crud_params(compiler, stmt, local_stmt_type, **kw): restore_isdelete = compiler.isdelete should_restore = ( - restore_isinsert or restore_isupdate or restore_isdelete - ) or len(compiler.stack) > 1 + (restore_isinsert or restore_isupdate or restore_isdelete) + or len(compiler.stack) > 1 + or "visiting_cte" in kw + ) if local_stmt_type is ISINSERT: compiler.isupdate = False -- cgit v1.2.1