-
Notifications
You must be signed in to change notification settings - Fork 349
fix(athena): skip retry of deterministic errors with configurable timeout handling #1814
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
084af8d
fix(athena): skip retry on query timeout
dtaniwaki 1e2ddf5
Merge branch 'main' into fix/no-retry-on-query-timeout
dtaniwaki 0e120ff
refactor(athena): simplify retry predicate to boolean expression
dtaniwaki 0e8d143
test(athena): add unit tests for cursor retry logic
dtaniwaki fca2a7d
style(athena): fix black formatting in test_cursor_retry
dtaniwaki 3412625
Merge branch 'main' into fix/no-retry-on-query-timeout
dtaniwaki 4bc4eb7
Merge branch 'main' into fix/no-retry-on-query-timeout
colin-k-rogers 8785e86
feat(athena): skip retry of deterministic errors with configurable ti…
dtaniwaki 1457242
Merge branch 'main' into fix/no-retry-on-query-timeout
colin-k-rogers f3fe877
Merge branch 'main' into fix/no-retry-on-query-timeout
dtaniwaki 1ed9a28
Merge branch 'main' into fix/no-retry-on-query-timeout
colin-k-rogers 6ac6bee
Merge branch 'main' into fix/no-retry-on-query-timeout
colin-k-rogers 33a6838
Merge branch 'main' into fix/no-retry-on-query-timeout
colin-k-rogers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| kind: Fixes | ||
| body: Skip retry of deterministic errors with configurable timeout handling. | ||
| time: 2026-03-30T09:55:39.69696+09:00 | ||
| custom: | ||
| Author: dtaniwaki | ||
| Issue: "1813 1820" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
| from pyathena.error import OperationalError | ||
| from pyathena.util import RetryConfig | ||
|
|
||
| from dbt.adapters.athena.connections import AthenaCursor | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def athena_cursor(): | ||
| connection = MagicMock() | ||
| connection.cursor_kwargs = {"num_iceberg_retries": 0} | ||
| retry_config = RetryConfig(attempt=3, max_delay=0, exponential_base=1) | ||
| cursor = AthenaCursor( | ||
| connection=connection, | ||
| converter=MagicMock(), | ||
| formatter=MagicMock(), | ||
| retry_config=retry_config, | ||
| s3_staging_dir="s3://test/", | ||
| schema_name="test_schema", | ||
| catalog_name="test_catalog", | ||
| work_group="test_wg", | ||
| poll_interval=0, | ||
| encryption_option=None, | ||
| kms_key=None, | ||
| kill_on_interrupt=False, | ||
| result_reuse_enable=False, | ||
| result_reuse_minutes=0, | ||
| ) | ||
| return cursor | ||
|
|
||
|
|
||
| class TestAthenaCursorRetry: | ||
| def test_retry_on_query_timeout_by_default(self, athena_cursor): | ||
| with patch.object( | ||
| athena_cursor, "_execute", side_effect=OperationalError("Query timeout") | ||
| ): | ||
| with pytest.raises(OperationalError, match="Query timeout"): | ||
| athena_cursor.execute("SELECT 1") | ||
| assert athena_cursor._execute.call_count == 3 | ||
|
|
||
| def test_no_retry_on_query_timeout_when_skip_enabled(self, athena_cursor): | ||
| athena_cursor.connection.cursor_kwargs["skip_retry_on_query_timeout"] = True | ||
| with patch.object( | ||
| athena_cursor, "_execute", side_effect=OperationalError("Query timeout") | ||
| ): | ||
| with pytest.raises(OperationalError, match="Query timeout"): | ||
| athena_cursor.execute("SELECT 1") | ||
| assert athena_cursor._execute.call_count == 1 | ||
|
|
||
| def test_no_retry_on_query_exhausted_resources(self, athena_cursor): | ||
| with patch.object( | ||
| athena_cursor, "_execute", side_effect=OperationalError("Query exhausted resources") | ||
| ): | ||
| with pytest.raises(OperationalError, match="Query exhausted resources"): | ||
| athena_cursor.execute("SELECT 1") | ||
| assert athena_cursor._execute.call_count == 1 | ||
|
|
||
|
dtaniwaki marked this conversation as resolved.
|
||
| def test_no_retry_on_too_many_open_partitions_when_catch_enabled(self, athena_cursor): | ||
| with patch.object( | ||
| athena_cursor, "_execute", side_effect=OperationalError("TOO_MANY_OPEN_PARTITIONS") | ||
| ): | ||
| with pytest.raises(OperationalError, match="TOO_MANY_OPEN_PARTITIONS"): | ||
| athena_cursor.execute("SELECT 1", catch_partitions_limit=True) | ||
| assert athena_cursor._execute.call_count == 1 | ||
|
|
||
| def test_retry_on_too_many_open_partitions_when_catch_disabled(self, athena_cursor): | ||
| with patch.object( | ||
| athena_cursor, "_execute", side_effect=OperationalError("TOO_MANY_OPEN_PARTITIONS") | ||
| ): | ||
| with pytest.raises(OperationalError, match="TOO_MANY_OPEN_PARTITIONS"): | ||
| athena_cursor.execute("SELECT 1", catch_partitions_limit=False) | ||
| assert athena_cursor._execute.call_count == 3 | ||
|
|
||
| def test_retry_on_transient_error(self, athena_cursor): | ||
| with patch.object( | ||
| athena_cursor, "_execute", side_effect=OperationalError("Some transient error") | ||
| ): | ||
| with pytest.raises(OperationalError, match="Some transient error"): | ||
| athena_cursor.execute("SELECT 1") | ||
| assert athena_cursor._execute.call_count == 3 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.