From 59e9276f04beef4459571cba4226f9d4eaef6be9 Mon Sep 17 00:00:00 2001 From: Lukas Banic Date: Mon, 10 Jun 2019 11:24:53 -0400 Subject: Accommodate value of None for ON DUPLICATE KEY UPDATE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed bug where MySQL ON DUPLICATE KEY UPDATE would not accommodate setting a column to the value NULL. Pull request courtesy Lukáš Banič. Fixes: #4715 Closes: #4716 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4716 Pull-request-sha: bfad6e6bdfb7d6dd5176deaf30d875f3d0f15e06 Change-Id: Ia8831cc171d131bf3824be8db4fd1d231231bba3 --- lib/sqlalchemy/dialects/mysql/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/sqlalchemy/dialects/mysql') diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index ad5ab288c..9aa80a5f4 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1232,15 +1232,15 @@ class MySQLCompiler(compiler.SQLCompiler): c for c in self.statement.table.c if c.key not in ordered_keys ] else: - # traverse in table column order cols = self.statement.table.c clauses = [] - for column in cols: - val = on_duplicate.update.get(column.key) - if val is None: - continue - elif coercions._is_literal(val): + # traverses through all table columns to preserve table column order + for column in (col for col in cols if col.key in on_duplicate.update): + + val = on_duplicate.update[column.key] + + if coercions._is_literal(val): val = elements.BindParameter(None, val, type_=column.type) value_text = self.process(val.self_group(), use_schema=False) elif isinstance(val, elements.BindParameter) and val.type._isnull: -- cgit v1.2.1