Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add InterfaceError to retryable_exceptions #895

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240806-163017.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: add InterfaceError to retryable_exceptions
time: 2024-08-06T16:30:17.348677-07:00
custom:
Author: colin-rogers-dbt
Issue: "661"
1 change: 1 addition & 0 deletions dbt/adapters/redshift/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def exponential_backoff(attempt: int):
redshift_connector.OperationalError,
redshift_connector.DatabaseError,
redshift_connector.DataError,
redshift_connector.InterfaceError,
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
]

open_connection = cls.retry_connection(
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from multiprocessing import get_context
from unittest import TestCase, mock

import pytest
from dbt.adapters.exceptions import FailedToConnectError
from unittest.mock import MagicMock, call

import redshift_connector

from dbt.adapters.redshift import (
Plugin as RedshiftPlugin,
RedshiftAdapter,
RedshiftCredentials,
)
from tests.unit.utils import (
config_from_parts_or_dicts,
Expand Down Expand Up @@ -128,3 +132,32 @@ def test_backend_pid_used_in_pg_terminate_backend(self):
call(f"select pg_terminate_backend({backend_pid})"),
]
)

def test_retry_able_exceptions_trigger_retry(self):
with mock.patch.object(self.adapter.connections, "add_query") as add_query:
connection_mock = mock_connection("model", state="closed")
connection_mock.credentials = RedshiftCredentials.from_dict(
{
"type": "redshift",
"dbname": "redshift",
"user": "root",
"host": "thishostshouldnotexist.test.us-east-1",
"pass": "password",
"port": 5439,
"schema": "public",
"retries": 2,
}
)

connect_mock = MagicMock()
connect_mock.side_effect = [
redshift_connector.InterfaceError("retryable interface error<1>"),
redshift_connector.InterfaceError("retryable interface error<2>"),
redshift_connector.InterfaceError("retryable interface error<3>"),
]

with mock.patch("redshift_connector.connect", connect_mock):
with pytest.raises(FailedToConnectError) as e:
connection = self.adapter.connections.open(connection_mock)
assert str(e.value) == "Database Error\n retryable interface error<3>"
assert connect_mock.call_count == 3
Loading