From 901f7a2b534e4bbc88d7c6894541223cb0dd968d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 17 Apr 2021 00:30:29 -0400 Subject: pass asfrom correctly in compilers Fixed an argument error in the default and PostgreSQL compilers that would interfere with an UPDATE..FROM or DELETE..FROM..USING statement that was then SELECTed from as a CTE. The incorrect pattern was also fixed in the mysql and sybase dialects. MySQL supports CTEs but not "returning". Fixes: #6303 Change-Id: Ic94805611a5ec443749fb6b1fd8a1326b0d83ef7 --- lib/sqlalchemy/dialects/mysql/base.py | 6 ++++-- lib/sqlalchemy/dialects/postgresql/base.py | 6 ++++-- lib/sqlalchemy/dialects/sybase/base.py | 3 ++- lib/sqlalchemy/sql/compiler.py | 6 ++++-- 4 files changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index c5113b054..d4c70a78e 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1783,8 +1783,9 @@ class MySQLCompiler(compiler.SQLCompiler): return None def update_tables_clause(self, update_stmt, from_table, extra_froms, **kw): + kw["asfrom"] = True return ", ".join( - t._compiler_dispatch(self, asfrom=True, **kw) + t._compiler_dispatch(self, **kw) for t in [from_table] + list(extra_froms) ) @@ -1806,8 +1807,9 @@ class MySQLCompiler(compiler.SQLCompiler): self, delete_stmt, from_table, extra_froms, from_hints, **kw ): """Render the DELETE .. USING clause specific to MySQL.""" + kw["asfrom"] = True return "USING " + ", ".join( - t._compiler_dispatch(self, asfrom=True, fromhints=from_hints, **kw) + t._compiler_dispatch(self, fromhints=from_hints, **kw) for t in [from_table] + extra_froms ) diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 0e9968031..47a933479 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -2420,8 +2420,9 @@ class PGCompiler(compiler.SQLCompiler): def update_from_clause( self, update_stmt, from_table, extra_froms, from_hints, **kw ): + kw["asfrom"] = True return "FROM " + ", ".join( - t._compiler_dispatch(self, asfrom=True, fromhints=from_hints, **kw) + t._compiler_dispatch(self, fromhints=from_hints, **kw) for t in extra_froms ) @@ -2429,8 +2430,9 @@ class PGCompiler(compiler.SQLCompiler): self, delete_stmt, from_table, extra_froms, from_hints, **kw ): """Render the DELETE .. USING clause specific to PostgreSQL.""" + kw["asfrom"] = True return "USING " + ", ".join( - t._compiler_dispatch(self, asfrom=True, fromhints=from_hints, **kw) + t._compiler_dispatch(self, fromhints=from_hints, **kw) for t in extra_froms ) diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py index 7c10973e6..5b6aefe9e 100644 --- a/lib/sqlalchemy/dialects/sybase/base.py +++ b/lib/sqlalchemy/dialects/sybase/base.py @@ -564,8 +564,9 @@ class SybaseSQLCompiler(compiler.SQLCompiler): self, delete_stmt, from_table, extra_froms, from_hints, **kw ): """Render the DELETE .. FROM clause specific to Sybase.""" + kw["asfrom"] = True return "FROM " + ", ".join( - t._compiler_dispatch(self, asfrom=True, fromhints=from_hints, **kw) + t._compiler_dispatch(self, fromhints=from_hints, **kw) for t in [from_table] + extra_froms ) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 0c701cb52..b8e418d99 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -3881,16 +3881,18 @@ class StrSQLCompiler(SQLCompiler): def update_from_clause( self, update_stmt, from_table, extra_froms, from_hints, **kw ): + kw["asfrom"] = True return "FROM " + ", ".join( - t._compiler_dispatch(self, asfrom=True, fromhints=from_hints, **kw) + t._compiler_dispatch(self, fromhints=from_hints, **kw) for t in extra_froms ) def delete_extra_from_clause( self, update_stmt, from_table, extra_froms, from_hints, **kw ): + kw["asfrom"] = True return ", " + ", ".join( - t._compiler_dispatch(self, asfrom=True, fromhints=from_hints, **kw) + t._compiler_dispatch(self, fromhints=from_hints, **kw) for t in extra_froms ) -- cgit v1.2.1