diff --git a/.changes/unreleased/Features-20230921-153707.yaml b/.changes/unreleased/Features-20230921-153707.yaml new file mode 100644 index 000000000..cf2c60ad5 --- /dev/null +++ b/.changes/unreleased/Features-20230921-153707.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Support storing test failures as views +time: 2023-09-21T15:37:07.970722-04:00 +custom: + Author: mikealfare + Issue: "6914" diff --git a/.changes/unreleased/Fixes-20230807-174409.yaml b/.changes/unreleased/Fixes-20230807-174409.yaml new file mode 100644 index 000000000..ad4f11b42 --- /dev/null +++ b/.changes/unreleased/Fixes-20230807-174409.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Use the PID to terminate the session +time: 2023-08-07T17:44:09.15097-06:00 +custom: + Author: dbeatty10 + Issue: "553" diff --git a/dbt/adapters/redshift/connections.py b/dbt/adapters/redshift/connections.py index 83d05b587..0c9d1b7ed 100644 --- a/dbt/adapters/redshift/connections.py +++ b/dbt/adapters/redshift/connections.py @@ -240,8 +240,9 @@ class RedshiftConnectionManager(SQLConnectionManager): def _get_backend_pid(self): sql = "select pg_backend_pid()" _, cursor = self.add_query(sql) + res = cursor.fetchone() - return res + return res[0] def cancel(self, connection: Connection): try: @@ -253,9 +254,10 @@ def cancel(self, connection: Connection): raise sql = f"select pg_terminate_backend({pid})" - _, cursor = self.add_query(sql) - res = cursor.fetchone() - logger.debug(f"Cancel query '{connection.name}': {res}") + cursor = connection.handle.cursor() + logger.debug(f"Cancel query on: '{connection.name}' with PID: {pid}") + logger.debug(sql) + cursor.execute(sql) @classmethod def get_response(cls, cursor: redshift_connector.Cursor) -> AdapterResponse: diff --git a/tests/functional/adapter/test_store_test_failures.py b/tests/functional/adapter/test_store_test_failures.py index 5d6b70fbb..7f591654e 100644 --- a/tests/functional/adapter/test_store_test_failures.py +++ b/tests/functional/adapter/test_store_test_failures.py @@ -1,7 +1,32 @@ +from dbt.tests.adapter.store_test_failures_tests import basic from dbt.tests.adapter.store_test_failures_tests.test_store_test_failures import ( TestStoreTestFailures, ) -class RedshiftTestStoreTestFailures(TestStoreTestFailures): +class TestRedshiftTestStoreTestFailures(TestStoreTestFailures): + pass + + +class TestStoreTestFailuresAsInteractions(basic.StoreTestFailuresAsInteractions): + pass + + +class TestStoreTestFailuresAsProjectLevelOff(basic.StoreTestFailuresAsProjectLevelOff): + pass + + +class TestStoreTestFailuresAsProjectLevelView(basic.StoreTestFailuresAsProjectLevelView): + pass + + +class TestStoreTestFailuresAsGeneric(basic.StoreTestFailuresAsGeneric): + pass + + +class TestStoreTestFailuresAsProjectLevelEphemeral(basic.StoreTestFailuresAsProjectLevelEphemeral): + pass + + +class TestStoreTestFailuresAsExceptions(basic.StoreTestFailuresAsExceptions): pass diff --git a/tests/unit/test_redshift_adapter.py b/tests/unit/test_redshift_adapter.py index c31366a1e..1edea565e 100644 --- a/tests/unit/test_redshift_adapter.py +++ b/tests/unit/test_redshift_adapter.py @@ -471,14 +471,13 @@ def test_cancel_open_connections_single(self): with mock.patch.object(self.adapter.connections, "add_query") as add_query: query_result = mock.MagicMock() cursor = mock.Mock() - cursor.fetchone.return_value = 42 + cursor.fetchone.return_value = (42,) add_query.side_effect = [(None, cursor), (None, query_result)] self.assertEqual(len(list(self.adapter.cancel_open_connections())), 1) add_query.assert_has_calls( [ call("select pg_backend_pid()"), - call("select pg_terminate_backend(42)"), ] )