Skip to content

Commit 30d6ea4

Browse files
committed
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 b20faba. 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
1 parent 95aca1d commit 30d6ea4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/crate/client/sqlalchemy/tests/dict_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ class SqlAlchemyDictTypeTest(TestCase):
4040

4141
def setUp(self):
4242
self.engine = sa.create_engine('crate://')
43-
# FIXME: Deprecated with SA20.
44-
metadata = sa.MetaData(bind=self.engine)
43+
metadata = sa.MetaData()
4544
self.mytable = sa.Table('mytable', metadata,
4645
sa.Column('name', sa.String),
4746
sa.Column('data', Craty))
4847

49-
def assertSQL(self, expected_str, actual_expr):
48+
def assertSQL(self, expected_str, selectable):
49+
actual_expr = selectable.compile(bind=self.engine)
5050
self.assertEqual(expected_str, str(actual_expr).replace('\n', ''))
5151

5252
def test_select_with_dict_column(self):

0 commit comments

Comments
 (0)