diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-03 17:22:30 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-03 17:23:56 -0500 |
commit | 7fe400f54632835695f7b98f0c1a54424953dfad (patch) | |
tree | c8e1b22a62313011f2c6c0ee5611e01081a67bff /lib/sqlalchemy/sql/crud.py | |
parent | 4c81d99bab0e884473abfcb573772aa5d94264c7 (diff) | |
download | sqlalchemy-7fe400f54632835695f7b98f0c1a54424953dfad.tar.gz |
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
Diffstat (limited to 'lib/sqlalchemy/sql/crud.py')
-rw-r--r-- | lib/sqlalchemy/sql/crud.py | 6 |
1 files changed, 4 insertions, 2 deletions
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 |