From 94bfe664c5e9daa3bc76d6f423dd12b7949b2f76 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 26 Oct 2023 17:04:47 -0700 Subject: [PATCH] fix: pass None for retry in gapic calls (#881) --- google/cloud/bigtable/data/_async/_mutate_rows.py | 1 + google/cloud/bigtable/data/_async/_read_rows.py | 1 + google/cloud/bigtable/data/_async/client.py | 3 +++ .../cloud/bigtable_v2/services/bigtable/async_client.py | 4 ++-- google/cloud/bigtable_v2/services/bigtable/client.py | 4 ++-- tests/unit/data/_async/test__mutate_rows.py | 3 ++- tests/unit/data/_async/test_client.py | 9 ++++++++- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/google/cloud/bigtable/data/_async/_mutate_rows.py b/google/cloud/bigtable/data/_async/_mutate_rows.py index baae205d9..be84fac17 100644 --- a/google/cloud/bigtable/data/_async/_mutate_rows.py +++ b/google/cloud/bigtable/data/_async/_mutate_rows.py @@ -79,6 +79,7 @@ def __init__( table_name=table.table_name, app_profile_id=table.app_profile_id, metadata=metadata, + retry=None, ) # create predicate for determining which errors are retryable self.is_retryable = retries.if_exception_type( diff --git a/google/cloud/bigtable/data/_async/_read_rows.py b/google/cloud/bigtable/data/_async/_read_rows.py index 20b5618ea..90cc7e87c 100644 --- a/google/cloud/bigtable/data/_async/_read_rows.py +++ b/google/cloud/bigtable/data/_async/_read_rows.py @@ -140,6 +140,7 @@ def _read_rows_attempt(self) -> AsyncGenerator[Row, None]: self.request, timeout=next(self.attempt_timeout_gen), metadata=self._metadata, + retry=None, ) chunked_stream = self.chunk_stream(gapic_stream) return self.merge_rows(chunked_stream) diff --git a/google/cloud/bigtable/data/_async/client.py b/google/cloud/bigtable/data/_async/client.py index c6637581c..90939927e 100644 --- a/google/cloud/bigtable/data/_async/client.py +++ b/google/cloud/bigtable/data/_async/client.py @@ -837,6 +837,7 @@ async def execute_rpc(): app_profile_id=self.app_profile_id, timeout=next(attempt_timeout_gen), metadata=metadata, + retry=None, ) return [(s.row_key, s.offset_bytes) async for s in results] @@ -1089,6 +1090,7 @@ async def check_and_mutate_row( }, metadata=metadata, timeout=operation_timeout, + retry=None, ) return result.predicate_matched @@ -1142,6 +1144,7 @@ async def read_modify_write_row( }, metadata=metadata, timeout=operation_timeout, + retry=None, ) # construct Row from result return Row._from_pb(result.row) diff --git a/google/cloud/bigtable_v2/services/bigtable/async_client.py b/google/cloud/bigtable_v2/services/bigtable/async_client.py index abd82d4d8..a80be70af 100644 --- a/google/cloud/bigtable_v2/services/bigtable/async_client.py +++ b/google/cloud/bigtable_v2/services/bigtable/async_client.py @@ -40,9 +40,9 @@ from google.oauth2 import service_account # type: ignore try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore + OptionalRetry = Union[retries.Retry, object, None] # type: ignore from google.cloud.bigtable_v2.types import bigtable from google.cloud.bigtable_v2.types import data diff --git a/google/cloud/bigtable_v2/services/bigtable/client.py b/google/cloud/bigtable_v2/services/bigtable/client.py index b0efc8a0b..1c2e7b822 100644 --- a/google/cloud/bigtable_v2/services/bigtable/client.py +++ b/google/cloud/bigtable_v2/services/bigtable/client.py @@ -43,9 +43,9 @@ from google.oauth2 import service_account # type: ignore try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore + OptionalRetry = Union[retries.Retry, object, None] # type: ignore from google.cloud.bigtable_v2.types import bigtable from google.cloud.bigtable_v2.types import data diff --git a/tests/unit/data/_async/test__mutate_rows.py b/tests/unit/data/_async/test__mutate_rows.py index 08422abca..eae3483ed 100644 --- a/tests/unit/data/_async/test__mutate_rows.py +++ b/tests/unit/data/_async/test__mutate_rows.py @@ -93,9 +93,10 @@ def test_ctor(self): assert client.mutate_rows.call_count == 1 # gapic_fn should call with table details inner_kwargs = client.mutate_rows.call_args[1] - assert len(inner_kwargs) == 3 + assert len(inner_kwargs) == 4 assert inner_kwargs["table_name"] == table.table_name assert inner_kwargs["app_profile_id"] == table.app_profile_id + assert inner_kwargs["retry"] is None metadata = inner_kwargs["metadata"] assert len(metadata) == 1 assert metadata[0][0] == "x-goog-request-params" diff --git a/tests/unit/data/_async/test_client.py b/tests/unit/data/_async/test_client.py index c2c4b0615..4ae46da6e 100644 --- a/tests/unit/data/_async/test_client.py +++ b/tests/unit/data/_async/test_client.py @@ -1329,6 +1329,7 @@ async def test_read_rows_attempt_timeout( # check timeouts for _, call_kwargs in read_rows.call_args_list[:-1]: assert call_kwargs["timeout"] == per_request_t + assert call_kwargs["retry"] is None # last timeout should be adjusted to account for the time spent assert ( abs( @@ -1884,6 +1885,7 @@ async def test_sample_row_keys_default_timeout(self): _, kwargs = sample_row_keys.call_args assert abs(kwargs["timeout"] - expected_timeout) < 0.1 assert result == [] + assert kwargs["retry"] is None @pytest.mark.asyncio async def test_sample_row_keys_gapic_params(self): @@ -1905,11 +1907,12 @@ async def test_sample_row_keys_gapic_params(self): await table.sample_row_keys(attempt_timeout=expected_timeout) args, kwargs = sample_row_keys.call_args assert len(args) == 0 - assert len(kwargs) == 4 + assert len(kwargs) == 5 assert kwargs["timeout"] == expected_timeout assert kwargs["app_profile_id"] == expected_profile assert kwargs["table_name"] == table.table_name assert kwargs["metadata"] is not None + assert kwargs["retry"] is None @pytest.mark.parametrize("include_app_profile", [True, False]) @pytest.mark.asyncio @@ -2231,6 +2234,7 @@ async def test_bulk_mutate_rows(self, mutation_arg): ) assert kwargs["entries"] == [bulk_mutation._to_dict()] assert kwargs["timeout"] == expected_attempt_timeout + assert kwargs["retry"] is None @pytest.mark.asyncio async def test_bulk_mutate_rows_multiple_entries(self): @@ -2595,6 +2599,7 @@ async def test_check_and_mutate(self, gapic_result): ] assert request["app_profile_id"] == app_profile assert kwargs["timeout"] == operation_timeout + assert kwargs["retry"] is None @pytest.mark.asyncio async def test_check_and_mutate_bad_timeout(self): @@ -2678,6 +2683,7 @@ async def test_check_and_mutate_predicate_object(self): kwargs = mock_gapic.call_args[1] assert kwargs["request"]["predicate_filter"] == predicate_dict assert mock_predicate._to_dict.call_count == 1 + assert kwargs["retry"] is None @pytest.mark.asyncio async def test_check_and_mutate_mutations_parsing(self): @@ -2781,6 +2787,7 @@ async def test_read_modify_write_call_rule_args(self, call_rules, expected_rules assert mock_gapic.call_count == 1 found_kwargs = mock_gapic.call_args_list[0][1] assert found_kwargs["request"]["rules"] == expected_rules + assert found_kwargs["retry"] is None @pytest.mark.parametrize("rules", [[], None]) @pytest.mark.asyncio