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

Fixed bug in @retried when exception subtypes were not respected #484

Merged
merged 1 commit into from
Dec 19, 2023
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
7 changes: 5 additions & 2 deletions databricks/sdk/retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ def wrapper(*args, **kwargs):
retry_reason = 'throttled by platform'
elif is_retryable is not None:
retry_reason = is_retryable(err)
elif type(err) in on:
retry_reason = f'{type(err).__name__} is allowed to retry'
elif on is not None:
for err_type in on:
if not isinstance(err, err_type):
continue
retry_reason = f'{type(err).__name__} is allowed to retry'

if retry_reason is None:
# raise if exception is not retryable
Expand Down
11 changes: 11 additions & 0 deletions tests/test_retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from databricks.sdk.errors import NotFound, ResourceDoesNotExist
from databricks.sdk.retries import retried


Expand Down Expand Up @@ -41,6 +42,16 @@ def foo():
foo()


def test_match_on_subclass():
with pytest.raises(TimeoutError):

@retried(on=[NotFound], timeout=timedelta(seconds=0.5))
def foo():
raise ResourceDoesNotExist(...)

foo()


def test_propagates_outside_exception():
with pytest.raises(KeyError):

Expand Down
Loading