From 3045c0c258a87a63a54fed8446c28ed4b376eca3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 21 Jun 2021 18:13:55 -0400 Subject: apply render_schema_translates to identity insert directives Fixed bug where the "schema_translate_map" feature would fail to function correctly in conjunction with an INSERT into a table that has an IDENTITY column, where the value of the IDENTITY column were specified in the values of the INSERT thus triggering SQLAlchemy's feature of setting IDENTITY INSERT to "on"; it's in this directive where the schema translate map would fail to be honored. Fixes: #6658 Change-Id: I8235aa639dd465d038a2ad48e7a669f3e5c5c37c --- lib/sqlalchemy/dialects/mssql/base.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 750f3743b..4ca83a697 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1533,10 +1533,18 @@ class MSExecutionContext(default.DefaultExecutionContext): _result_strategy = None def _opt_encode(self, statement): + if not self.dialect.supports_unicode_statements: - return self.dialect._encoder(statement)[0] + encoded = self.dialect._encoder(statement)[0] else: - return statement + encoded = statement + + if self.compiled and self.compiled.schema_translate_map: + + rst = self.compiled.preparer._render_schema_translates + encoded = rst(encoded, self.compiled.schema_translate_map) + + return encoded def pre_exec(self): """Activate IDENTITY_INSERT if needed.""" -- cgit v1.2.1