diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-07-05 21:05:18 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-07-06 09:58:11 -0400 |
| commit | 370d73b4e4b3009ea5feed1341ead965f6aa98bb (patch) | |
| tree | d86d23568f0edc9b2c67210073c83bca99eaca7e /lib/sqlalchemy/dialects | |
| parent | 6e8c390c1b937d842893646fb59785eaa48b243b (diff) | |
| download | sqlalchemy-370d73b4e4b3009ea5feed1341ead965f6aa98bb.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
Diffstat (limited to 'lib/sqlalchemy/dialects')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 2a4362ccb..ed4139ad1 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1751,15 +1751,12 @@ class MSExecutionContext(default.DefaultExecutionContext): not isinstance(id_column.default, Sequence) ): insert_has_identity = True - compile_state = self.compiled.compile_state + compile_state = self.compiled.dml_compile_state self._enable_identity_insert = ( id_column.key in self.compiled_parameters[0] ) or ( compile_state._dict_parameters - and ( - id_column.key in compile_state._dict_parameters - or id_column in compile_state._dict_parameters - ) + and (id_column.key in compile_state._insert_col_keys) ) else: |
