Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring: Modularize CrateCompiler #498

Merged
merged 1 commit into from
Dec 27, 2022
Merged

Conversation

amotl
Copy link
Member

@amotl amotl commented Dec 25, 2022

About

By refactoring the SQLAlchemy 1.0-1.3 vs. 1.4 specialities of the CrateCompiler (visit_update and _get_crud_params) into dedicated modules, the new layout is more suitable for bringing in support for SQLAlchemy 2.0.

Details

Effectively, it moves code from crate.client.sqlalchemy.compiler into crate.client.sqlalchemy.compat.core{10,14}.

References

src/crate/client/sqlalchemy/compat/core10.py Fixed Show fixed Hide fixed
_column_as_key,
_getattr_col_key,
_col_bind_name,
) = _key_getters_for_crud_column(compiler, stmt)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function _key_getters_for_crud_column](1) with too few arguments; should be no fewer than 3.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL is comparing apples with oranges here and below. I think it does not get SQLAlchemy's versions right, and compares the wrong versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if it will get fixed by GH-499.

Copy link
Member Author

@amotl amotl Dec 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CodeQL will not be smart enough to handle this case, when a code base contains code which calls functions or methods in 3rd-party libraries with different signatures, because of their evolutions across different versions.

So, I think we will have to go with manually dismissing those Wrong number of arguments in a call admonitions. Please correct me if I am wrong.

Comment on lines +198 to +209
_scan_insert_from_select_cols(
compiler,
stmt,
parameters,
_getattr_col_key,
_column_as_key,
_col_bind_name,
check_columns,
values,
kw,
)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function _scan_insert_from_select_cols](1) with too few arguments; should be no fewer than 10.
Comment on lines +210 to +221
_scan_cols(
compiler,
stmt,
parameters,
_getattr_col_key,
_column_as_key,
_col_bind_name,
check_columns,
values,
kw,
)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function _scan_cols](1) with too few arguments; should be no fewer than 10.
"""

if stmt._has_multi_parameters:
values = _extend_values_for_multiparams(compiler, stmt, values, kw)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function _extend_values_for_multiparams](1) with too few arguments; should be no fewer than 6.
src/crate/client/sqlalchemy/compat/core14.py Fixed Show fixed Hide fixed
@amotl amotl marked this pull request as ready for review December 25, 2022 02:48
By refactoring the SQLAlchemy 1.0-1.3 vs. 1.4 specialities of the
`CrateCompiler` (`visit_update` and `_get_crud_params`) into dedicated
modules, the new layout is more suitable for bringing in support for
SQLAlchemy 2.0.

if self.ctes:
nesting_level = len(self.stack) if not toplevel else None
text = self._render_cte_clause(nesting_level=nesting_level) + text

Check failure

Code scanning / CodeQL

Wrong name for an argument in a call

Keyword argument 'nesting_level' is not a supported parameter name of [method SQLCompiler._render_cte_clause](1).
_column_as_key,
_getattr_col_key,
_col_bind_name,
) = getters = _key_getters_for_crud_column(compiler, stmt, compile_state)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function _key_getters_for_crud_column](1) with too many arguments; should be no more than 2.
Comment on lines +269 to +280
_scan_insert_from_select_cols(
compiler,
stmt,
compile_state,
parameters,
_getattr_col_key,
_column_as_key,
_col_bind_name,
check_columns,
values,
kw,
)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function _scan_insert_from_select_cols](1) with too many arguments; should be no more than 9.
Comment on lines +282 to +293
_scan_cols(
compiler,
stmt,
compile_state,
parameters,
_getattr_col_key,
_column_as_key,
_col_bind_name,
check_columns,
values,
kw,
)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function _scan_cols](1) with too many arguments; should be no more than 9.
Comment on lines +327 to +334
values = _extend_values_for_multiparams(
compiler,
stmt,
compile_state,
values,
_column_as_key,
kw,
)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function _extend_values_for_multiparams](1) with too many arguments; should be no more than 4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants