From 1a2997e7415413e507fd2472e5cdf28d4d32bdf8 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 21 Dec 2022 22:22:35 +0100 Subject: [PATCH] SA20: Fix SqlAlchemyDictTypeTest "Implicit" and "Connectionless" execution, and "bound metadata" have been removed beginning with SQLAlchemy 2.0 [1]. Earlier and contemporary versions of SQLAlchemy had the ability to associate an `Engine` with a `MetaData` object. This allowed a number of so-called "connectionless" execution patterns. That is no longer possible. Instead, the association with an `Engine` object has to be concluded differently. On this very spot, in the context of the `dict_test` test cases, the most easy fix was to move it to the invocation of the `compile()` method of the `selectable` instance, which is now returned by the `sqlalchemy.sql.*` primitives: expression = selectable.compile(bind=self.engine) This is needed, because otherwise, when not associating `Engine` with `MetaData` properly, `CrateDialect` would be bypassed, and the "paramstyle" [2] of SQLAlchemy's `DefaultDialect` would be used, which is actually "named" [3], as originally reflected per b20fabad0. This is probably wrong, because the CrateDB Python driver uses the "qmark" paramstyle [4]. [1] https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#implicit-and-connectionless-execution-bound-metadata-removed [2] https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.create_engine.params.paramstyle [3] https://github.com/sqlalchemy/sqlalchemy/blob/rel_2_0_0b4/lib/sqlalchemy/engine/default.py#L204 [4] https://github.com/crate/crate-python/blob/0.29.0/src/crate/client/__init__.py#L36 --- src/crate/client/sqlalchemy/tests/dict_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/crate/client/sqlalchemy/tests/dict_test.py b/src/crate/client/sqlalchemy/tests/dict_test.py index 5bd9ceed..dbec0eef 100644 --- a/src/crate/client/sqlalchemy/tests/dict_test.py +++ b/src/crate/client/sqlalchemy/tests/dict_test.py @@ -40,13 +40,13 @@ class SqlAlchemyDictTypeTest(TestCase): def setUp(self): self.engine = sa.create_engine('crate://') - # FIXME: Deprecated with SA20. - metadata = sa.MetaData(bind=self.engine) + metadata = sa.MetaData() self.mytable = sa.Table('mytable', metadata, sa.Column('name', sa.String), sa.Column('data', Craty)) - def assertSQL(self, expected_str, actual_expr): + def assertSQL(self, expected_str, selectable): + actual_expr = selectable.compile(bind=self.engine) self.assertEqual(expected_str, str(actual_expr).replace('\n', '')) def test_select_with_dict_column(self):