summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-07-05 21:05:18 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-07-05 22:02:43 -0400
commit844365266aeb2582d775d019c48e7ffa6113c673 (patch)
tree3223c0c65ef76fa4d892c468a47df4f0269023bf /lib/sqlalchemy/sql/compiler.py
parentd0308de0b67802b9e2e3faa8309d861545e38f86 (diff)
downloadsqlalchemy-844365266aeb2582d775d019c48e7ffa6113c673.tar.gz
generalize sql server check for id col to accommodate ORM cases
Fixed issues that prevented the new usage patterns for using DML with ORM objects presented at :ref:`orm_dml_returning_objects` from working correctly with the SQL Server pyodbc dialect. Here we add a step to look in compile_state._dict_values more thoroughly for the keys we need to determine "identity insert" or not, and also add a new compiler variable dml_compile_state so that we can skip the ORM's compile_state if present. Fixes: #8210 Change-Id: Idbd76bb3eb075c647dc6c1cb78f7315c821e15f7 (cherry picked from commit 5806428800d2f1ac775156f90497a2fc3a644f35)
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 477c199c1..667dd7d3d 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -402,6 +402,18 @@ class Compiled(object):
"""
+ dml_compile_state = None
+ """Optional :class:`.CompileState` assigned at the same point that
+ .isinsert, .isupdate, or .isdelete is assigned.
+
+ This will normally be the same object as .compile_state, with the
+ exception of cases like the :class:`.ORMFromStatementCompileState`
+ object.
+
+ .. versionadded:: 1.4.40
+
+ """
+
cache_key = None
_gen_time = None
@@ -3838,6 +3850,8 @@ class SQLCompiler(Compiled):
if toplevel:
self.isinsert = True
+ if not self.dml_compile_state:
+ self.dml_compile_state = compile_state
if not self.compile_state:
self.compile_state = compile_state
@@ -4008,6 +4022,8 @@ class SQLCompiler(Compiled):
toplevel = not self.stack
if toplevel:
self.isupdate = True
+ if not self.dml_compile_state:
+ self.dml_compile_state = compile_state
if not self.compile_state:
self.compile_state = compile_state
@@ -4134,6 +4150,8 @@ class SQLCompiler(Compiled):
toplevel = not self.stack
if toplevel:
self.isdelete = True
+ if not self.dml_compile_state:
+ self.dml_compile_state = compile_state
if not self.compile_state:
self.compile_state = compile_state