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

Add support for SQLAlchemy 2.0 #488

Merged
merged 8 commits into from
Feb 1, 2023
Merged

Add support for SQLAlchemy 2.0 #488

merged 8 commits into from
Feb 1, 2023

Conversation

amotl
Copy link
Member

@amotl amotl commented Dec 21, 2022

Based on #485 and #498, this patch concludes compatibility work with SQLAlchemy 2.0 12 (GH-465) 🎉.

Footnotes

  1. https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html

  2. https://docs.sqlalchemy.org/en/20/changelog/migration_20.html

src/crate/client/sqlalchemy/dialect.py Outdated Show resolved Hide resolved
Comment on lines -77 to +81
self.assertEqual(expected_bulk_args, bulk_args)
self.assertSequenceEqual(expected_bulk_args, bulk_args)
Copy link
Member Author

@amotl amotl Dec 21, 2022

Choose a reason for hiding this comment

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

With SA<2.0, bulk_args is a tuple, so expected_bulk_args was written as such. Now, with SA>=2.0, it is a list. Because this only concerns the call arguments to cursor.executemany(), which is invoked by SQLAlchemy, I think we do not need to put any kind of admonition notice about a breaking change into the changelog, as it looks like it will not concern the user of the library at all.

Please let me know if you think differently.

src/crate/client/sqlalchemy/tests/compiler_test.py Outdated Show resolved Hide resolved
@amotl amotl force-pushed the amo/sa-mitigate-deprecation-warnings branch from 386e246 to 7ef37c1 Compare December 21, 2022 23:52
@amotl amotl force-pushed the amo/sa-mitigate-deprecation-warnings branch from 1429658 to a4454d5 Compare December 22, 2022 12:36
@amotl amotl force-pushed the amo/sa-mitigate-deprecation-warnings branch from fe32a5e to b177b1e Compare December 23, 2022 23:44
@amotl amotl force-pushed the amo/sa20 branch 3 times, most recently from 5b21d71 to caf6b19 Compare December 24, 2022 00:14
@amotl amotl force-pushed the amo/sa-mitigate-deprecation-warnings branch from b177b1e to be93172 Compare December 25, 2022 00:26
@amotl amotl changed the base branch from amo/sa-mitigate-deprecation-warnings to master December 25, 2022 13:54
@amotl amotl changed the title Add support for SQLAlchemy 2.0 [STACK] Add support for SQLAlchemy 2.0 Dec 25, 2022
@amotl amotl changed the base branch from master to amo/sa-mitigate-deprecation-warnings December 27, 2022 11:38
@amotl amotl force-pushed the amo/sa-mitigate-deprecation-warnings branch from 639636f to 19dbf7d Compare December 29, 2022 13:09
Base automatically changed from amo/sa-mitigate-deprecation-warnings to master December 30, 2022 10:24
@amotl amotl force-pushed the amo/sa20 branch 2 times, most recently from 0bdf9f1 to f6f1bd3 Compare December 30, 2022 10:52
@amotl amotl changed the title [STACK] Add support for SQLAlchemy 2.0 Add support for SQLAlchemy 2.0 Dec 30, 2022
# [20] CrateDB patch end.

"""
# TODO: Complete SA20 migration.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this TODO get addressed with this PR?

Copy link
Member Author

@amotl amotl Jan 27, 2023

Choose a reason for hiding this comment

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

Hi. Thanks for spotting this leftover comment. I've spent another day on it, in order to mangle the parameter data into a shape that would be accepted by the new cast function, but wasn't able to make a cut.

So, I've just created GH-508 in order to track this issue, and eventually resolve it on behalf of a subsequent iteration, and to unblock this patch. Any help on this topic is very welcome.

#
# sqlalchemy.exc.CompileError: Unconsumed column names: characters_name
#
# TODO: Investigate why this is actually happening and eventually mitigate
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Member Author

@amotl amotl Jan 27, 2023

Choose a reason for hiding this comment

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

This is an issue we are carrying over since the initial implementation of the CrateDB SQLAlchemy dialect. I've also tried to remedy it a few times, but did not manage to improve it yet.

At least, I've created GH-509 now, in order to highlight this spot more prominently. I'd also recommend to investigate it on behalf on a subsequent iteration, in order not to block this patch. Any help on this will be well received.

@amotl

This comment was marked as outdated.

References:
- `sqlalchemy.sql.compiler.SQLCompiler.visit_update`
- `sqlalchemy.sql.crud._get_crud_params`

Vendored from SQLAlchemy 2.0.0b4, released on Dec 6, 2022.
This effectively concludes the support for SQLAlchemy 2.0, by
implementing the same strategy as for the previous versions:
After vendoring the vanilla dialect's compiler's `visit_update` and
`_get_crud_params` methods, they are patched at a few spots to
accommodate CrateDB's features.

The changed behavior is mostly for running update statements on nested
`OBJECT` or `ARRAY` data types.
Currently, this is 2.0.0b4.
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.
bootstrap.sh Outdated
@@ -70,7 +70,7 @@ function setup_package() {
if [ "${SQLALCHEMY_VERSION}" = "latest" ]; then
pip install "sqlalchemy" --upgrade
else
pip install "sqlalchemy==${SQLALCHEMY_VERSION}"
pip install "sqlalchemy==${SQLALCHEMY_VERSION}" --pre
Copy link
Member

Choose a reason for hiding this comment

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

Is the --pre still required?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for spotting. I don't think so, so I've updated 71a7f0a correspondingly.

@@ -25,3 +25,4 @@
SA_VERSION = V(sa.__version__)

SA_1_4 = V('1.4.0b1')
SA_2_0 = V('2.0.0b1')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
SA_2_0 = V('2.0.0b1')
SA_2_0 = V('2.0.0')

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. See also 71a7f0a.

@amotl amotl merged commit 4327b97 into master Feb 1, 2023
@amotl amotl deleted the amo/sa20 branch February 1, 2023 16:48
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