diff --git a/lgtm.yml b/lgtm.yml new file mode 100644 index 00000000..f25f90ad --- /dev/null +++ b/lgtm.yml @@ -0,0 +1,7 @@ +queries: + + # Suppress some LGTM warnings. + + # A module is imported with the "import" and "import from" statements. + # https://lgtm.com/rules/1818040193/ + - exclude: py/import-and-import-from diff --git a/src/crate/client/sqlalchemy/compiler.py b/src/crate/client/sqlalchemy/compiler.py index 62c92037..7eb5eb0c 100644 --- a/src/crate/client/sqlalchemy/compiler.py +++ b/src/crate/client/sqlalchemy/compiler.py @@ -23,8 +23,7 @@ from collections import defaultdict import sqlalchemy as sa -from sqlalchemy.sql import crud, selectable -from sqlalchemy.sql import compiler +from sqlalchemy.sql import compiler, crud, selectable from .types import MutableDict from .sa_version import SA_VERSION, SA_1_4 @@ -400,6 +399,10 @@ def visit_update_14(self, update_stmt, **kw): else: dialect_hints = None + if update_stmt._independent_ctes: + for cte in update_stmt._independent_ctes: + cte._compiler_dispatch(self, **kw) + text += table_text text += " SET " @@ -459,8 +462,9 @@ def visit_update_14(self, update_stmt, **kw): update_stmt, self.returning or update_stmt._returning ) - if self.ctes and toplevel: - text = self._render_cte_clause() + text + if self.ctes: + nesting_level = len(self.stack) if not toplevel else None + text = self._render_cte_clause(nesting_level=nesting_level) + text self.stack.pop(-1) @@ -481,7 +485,7 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw): from sqlalchemy.sql.crud import _create_bind_param from sqlalchemy.sql.crud import REQUIRED from sqlalchemy.sql.crud import _get_stmt_parameter_tuples_params - from sqlalchemy.sql.crud import _get_multitable_params + from sqlalchemy.sql.crud import _get_update_multitable_params from sqlalchemy.sql.crud import _scan_insert_from_select_cols from sqlalchemy.sql.crud import _scan_cols from sqlalchemy import exc # noqa: F401 @@ -561,7 +565,7 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw): # special logic that only occurs for multi-table UPDATE # statements if compile_state.isupdate and compile_state.is_multitable: - _get_multitable_params( + _get_update_multitable_params( compiler, stmt, compile_state, @@ -620,9 +624,18 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw): if compile_state._has_multi_parameters: values = _extend_values_for_multiparams( - compiler, stmt, compile_state, values, kw + compiler, + stmt, + compile_state, + values, + _column_as_key, + kw, ) - elif not values and compiler.for_executemany: + elif ( + not values + and compiler.for_executemany # noqa: W503 + and compiler.dialect.supports_default_metavalue # noqa: W503 + ): # convert an "INSERT DEFAULT VALUES" # into INSERT (firstcol) VALUES (DEFAULT) which can be turned # into an in-place multi values. This supports diff --git a/src/crate/client/sqlalchemy/dialect.py b/src/crate/client/sqlalchemy/dialect.py index 1a2017fa..15373127 100644 --- a/src/crate/client/sqlalchemy/dialect.py +++ b/src/crate/client/sqlalchemy/dialect.py @@ -25,7 +25,7 @@ # FIXME: Workaround to be able to use SQLAlchemy 1.4. # Caveat: This purges the ``cresultproxy`` extension # at runtime, so it will impose a speed bump. -import crate.client.sqlalchemy.monkey # noqa:F401 +import crate.client.sqlalchemy.monkey # noqa:F401, lgtm[py/unused-import] from sqlalchemy import types as sqltypes from sqlalchemy.engine import default, reflection diff --git a/src/crate/client/sqlalchemy/types.py b/src/crate/client/sqlalchemy/types.py index a343d5e3..a01a68d1 100644 --- a/src/crate/client/sqlalchemy/types.py +++ b/src/crate/client/sqlalchemy/types.py @@ -168,7 +168,7 @@ class Any(expression.ColumnElement): def __init__(self, left, right, operator=operators.eq): self.type = sqltypes.Boolean() - self.left = expression._literal_as_binds(left) + self.left = expression.literal(left) self.right = right self.operator = operator