diff options
| author | Lukas Banic <luko@lingea.cz> | 2019-06-10 11:24:53 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-10 13:26:34 -0400 |
| commit | 59e9276f04beef4459571cba4226f9d4eaef6be9 (patch) | |
| tree | e7eb8655f83f3da7a067e527cc0ae43ce6d5ce72 /lib/sqlalchemy/dialects | |
| parent | e2521b595ae8b5b4ca8147c5ee13e2fc0f597e63 (diff) | |
| download | sqlalchemy-59e9276f04beef4459571cba4226f9d4eaef6be9.tar.gz | |
Accommodate value of None for ON DUPLICATE KEY UPDATE
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
Diffstat (limited to 'lib/sqlalchemy/dialects')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 12 |
1 files changed, 6 insertions, 6 deletions
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: |
