diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-10-19 10:19:29 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-10-19 13:13:15 -0400 |
| commit | 3e49b8d0519aa024842206a2fb664a4ad83796d6 (patch) | |
| tree | 9eb3cf01a68c42bb77a0bf76e99865d7c6370262 /lib/sqlalchemy/dialects/mysql/base.py | |
| parent | 296c84313ab29bf9599634f38caaf7dd092e4e23 (diff) | |
| download | sqlalchemy-3e49b8d0519aa024842206a2fb664a4ad83796d6.tar.gz | |
Ensure no compiler visit method tries to access .statement
Fixed structural compiler issue where some constructs such as MySQL /
PostgreSQL "on conflict / on duplicate key" would rely upon the state of
the :class:`_sql.Compiler` object being fixed against their statement as
the top level statement, which would fail in cases where those statements
are branched from a different context, such as a DDL construct linked to a
SQL statement.
Fixes: #5656
Change-Id: I568bf40adc7edcf72ea6c7fd6eb9d07790de189e
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/base.py')
| -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 3e6c676ab..77f65799c 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1461,6 +1461,8 @@ class MySQLCompiler(compiler.SQLCompiler): return self._render_json_extract_from_binary(binary, operator, **kw) def visit_on_duplicate_key_update(self, on_duplicate, **kw): + statement = self.current_executable + if on_duplicate._parameter_ordering: parameter_ordering = [ coercions.expect(roles.DMLColumnRole, key) @@ -1468,14 +1470,12 @@ class MySQLCompiler(compiler.SQLCompiler): ] ordered_keys = set(parameter_ordering) cols = [ - self.statement.table.c[key] + statement.table.c[key] for key in parameter_ordering - if key in self.statement.table.c - ] + [ - c for c in self.statement.table.c if c.key not in ordered_keys - ] + if key in statement.table.c + ] + [c for c in statement.table.c if c.key not in ordered_keys] else: - cols = self.statement.table.c + cols = statement.table.c clauses = [] # traverses through all table columns to preserve table column order |
