From fd28b35263b3e3ee1fac43e2351ed02c8f3b02a5 Mon Sep 17 00:00:00 2001 From: julio-romero <77467500+julio-romero@users.noreply.github.com> Date: Sat, 5 Aug 2023 13:43:17 -0600 Subject: [PATCH] =?UTF-8?q?Update=20connections.py=20so=20it=20doesn?= =?UTF-8?q?=E2=80=99t=20run=20anything=20after=20its=20canceled=20(#716)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update connections.py so it doesn’t run anything after its canceled * Update expected cancellation query * Changelog entry --------- Co-authored-by: Mike Alfare <13974384+mikealfare@users.noreply.github.com> Co-authored-by: Doug Beatty --- .changes/unreleased/Fixes-20230804-175222.yaml | 6 ++++++ dbt/adapters/snowflake/connections.py | 2 +- tests/unit/test_snowflake_adapter.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Fixes-20230804-175222.yaml diff --git a/.changes/unreleased/Fixes-20230804-175222.yaml b/.changes/unreleased/Fixes-20230804-175222.yaml new file mode 100644 index 000000000..b222b21ac --- /dev/null +++ b/.changes/unreleased/Fixes-20230804-175222.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Cancel all queries when terminating dbt +time: 2023-08-04T17:52:22.956964-06:00 +custom: + Author: julio-romero + Issue: "711" diff --git a/dbt/adapters/snowflake/connections.py b/dbt/adapters/snowflake/connections.py index 5c1ba576b..3272eee55 100644 --- a/dbt/adapters/snowflake/connections.py +++ b/dbt/adapters/snowflake/connections.py @@ -384,7 +384,7 @@ def cancel(self, connection): connection_name = connection.name - sql = "select system$abort_session({})".format(sid) + sql = "select system$cancel_all_queries({})".format(sid) logger.debug("Cancelling query '{}' ({})".format(connection_name, sid)) diff --git a/tests/unit/test_snowflake_adapter.py b/tests/unit/test_snowflake_adapter.py index dd1fb8b02..85bbb3859 100644 --- a/tests/unit/test_snowflake_adapter.py +++ b/tests/unit/test_snowflake_adapter.py @@ -265,7 +265,7 @@ def test_cancel_open_connections_single(self): self.assertEqual(len(list(self.adapter.cancel_open_connections())), 1) - add_query.assert_called_once_with("select system$abort_session(42)") + add_query.assert_called_once_with("select system$cancel_all_queries(42)") def test_client_session_keep_alive_false_by_default(self): conn = self.adapter.connections.set_connection_name(name="new_connection_with_new_config")