From 5833ba55f85dc9426bf8a85957268ba770b0232d Mon Sep 17 00:00:00 2001 From: Jon Betts Date: Wed, 11 Jan 2023 18:43:23 +0000 Subject: [PATCH] Fix warnings raised by incompatibilities with SQLAlchemy 2.x I believe this should mean we are compatible for the upgrade with this library. --- .cookiecutter/includes/tox/setenv | 1 + src/data_tasks/sql_query.py | 5 +---- tests/unit/data_tasks/sql_query_test.py | 3 +-- tox.ini | 1 + 4 files changed, 4 insertions(+), 6 deletions(-) create mode 100644 .cookiecutter/includes/tox/setenv diff --git a/.cookiecutter/includes/tox/setenv b/.cookiecutter/includes/tox/setenv new file mode 100644 index 0000000..4f96eb4 --- /dev/null +++ b/.cookiecutter/includes/tox/setenv @@ -0,0 +1 @@ +SQLALCHEMY_WARN_20=1 diff --git a/src/data_tasks/sql_query.py b/src/data_tasks/sql_query.py index 88c7ca2..1da2151 100644 --- a/src/data_tasks/sql_query.py +++ b/src/data_tasks/sql_query.py @@ -33,13 +33,10 @@ def execute(self, connection: Connection, dry_run=False, parameters=None): """Execute this query in the given session.""" with self.timing.time_it(): - if not parameters: - parameters = {} - if dry_run: return - cursor = connection.execute(sa.text(self.text), **parameters) + cursor = connection.execute(sa.text(self.text), parameters or {}) if cursor.returns_rows: # pylint:disable=protected-access self.columns = cursor._metadata.keys diff --git a/tests/unit/data_tasks/sql_query_test.py b/tests/unit/data_tasks/sql_query_test.py index 3d94add..36d312f 100644 --- a/tests/unit/data_tasks/sql_query_test.py +++ b/tests/unit/data_tasks/sql_query_test.py @@ -70,8 +70,7 @@ def assert_query_null_pre_execute(self, query): @fixture def connection(self, db_session): - with db_session.bind.connect() as connection: - yield connection + return db_session.bind @fixture def query(self): diff --git a/tox.ini b/tox.ini index b35f75e..27ae324 100644 --- a/tox.ini +++ b/tox.ini @@ -16,6 +16,7 @@ setenv = OBJC_DISABLE_INITIALIZE_FORK_SAFETY = YES dev: DATABASE_URL = {env:DATABASE_URL:postgresql://postgres@localhost:5439/postgres} tests,functests: TEST_DATABASE_URL = {env:TEST_DATABASE_URL:postgresql://postgres@localhost:5439/data_tasks_test} + SQLALCHEMY_WARN_20=1 passenv = HOME PYTEST_ADDOPTS