From dfcdd0fcfe1975ee755b0b5c47f5769dbf1e4a70 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 2 Jan 2023 13:41:24 +0100 Subject: [PATCH] SA20: Divert `CrateCompiler.returning_clause` to SA10/SA14 compilers Apparently, `PGCompiler` does not have a specific implementation for `returning_clause`, starting with SA20. On the other hand, the generic implementation changed its method signature, that's why CodeQL would croak otherwise. --- src/crate/client/sqlalchemy/compat/core10.py | 7 +++++++ src/crate/client/sqlalchemy/compat/core14.py | 7 +++++++ src/crate/client/sqlalchemy/compiler.py | 6 ------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/crate/client/sqlalchemy/compat/core10.py b/src/crate/client/sqlalchemy/compat/core10.py index e8d7deab..92c62dd8 100644 --- a/src/crate/client/sqlalchemy/compat/core10.py +++ b/src/crate/client/sqlalchemy/compat/core10.py @@ -20,6 +20,7 @@ # software solely pursuant to the terms of the relevant commercial agreement. import sqlalchemy as sa +from sqlalchemy.dialects.postgresql.base import PGCompiler from sqlalchemy.sql.crud import (REQUIRED, _create_bind_param, _extend_values_for_multiparams, _get_multitable_params, @@ -32,6 +33,12 @@ class CrateCompilerSA10(CrateCompiler): + def returning_clause(self, stmt, returning_cols): + """ + Generate RETURNING clause, PostgreSQL-compatible. + """ + return PGCompiler.returning_clause(self, stmt, returning_cols) + def visit_update(self, update_stmt, **kw): """ used to compile expressions diff --git a/src/crate/client/sqlalchemy/compat/core14.py b/src/crate/client/sqlalchemy/compat/core14.py index f37ea827..2dd6670a 100644 --- a/src/crate/client/sqlalchemy/compat/core14.py +++ b/src/crate/client/sqlalchemy/compat/core14.py @@ -20,6 +20,7 @@ # software solely pursuant to the terms of the relevant commercial agreement. import sqlalchemy as sa +from sqlalchemy.dialects.postgresql.base import PGCompiler from sqlalchemy.sql import selectable from sqlalchemy.sql.crud import (REQUIRED, _create_bind_param, _extend_values_for_multiparams, @@ -33,6 +34,12 @@ class CrateCompilerSA14(CrateCompiler): + def returning_clause(self, stmt, returning_cols): + """ + Generate RETURNING clause, PostgreSQL-compatible. + """ + return PGCompiler.returning_clause(self, stmt, returning_cols) + def visit_update(self, update_stmt, **kw): compile_state = update_stmt._compile_state_factory( diff --git a/src/crate/client/sqlalchemy/compiler.py b/src/crate/client/sqlalchemy/compiler.py index efa06a0c..7e6dad7d 100644 --- a/src/crate/client/sqlalchemy/compiler.py +++ b/src/crate/client/sqlalchemy/compiler.py @@ -221,12 +221,6 @@ def visit_any(self, element, **kw): self.process(element.right, **kw) ) - def returning_clause(self, stmt, returning_cols): - """ - Generate RETURNING clause, PostgreSQL-compatible. - """ - return PGCompiler.returning_clause(self, stmt, returning_cols) - def limit_clause(self, select, **kw): """ Generate OFFSET / LIMIT clause, PostgreSQL-compatible.