Skip to content

Commit

Permalink
SA20: Fix SqlAlchemyDictTypeTest
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
amotl committed Dec 22, 2022
1 parent ae1d125 commit 1a2997e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/crate/client/sqlalchemy/tests/dict_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1a2997e

Please sign in to comment.