From e8677dffc4afea688d84b169fc9f82721e450114 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 24 Oct 2023 14:59:51 -0700 Subject: [PATCH 1/4] fix: pass None for retry in gapic calls --- 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 +++ 3 files changed, 5 insertions(+) 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 e5be1b2d3..258532c47 100644 --- a/google/cloud/bigtable/data/_async/client.py +++ b/google/cloud/bigtable/data/_async/client.py @@ -857,6 +857,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] @@ -1120,6 +1121,7 @@ async def check_and_mutate_row( }, metadata=metadata, timeout=operation_timeout, + retry=None, ) return result.predicate_matched @@ -1173,6 +1175,7 @@ async def read_modify_write_row( }, metadata=metadata, timeout=operation_timeout, + retry=None, ) # construct Row from result return Row._from_pb(result.row) From c0c89016a74810d7bb3d4552dbbe92eca41c6c92 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 24 Oct 2023 15:12:47 -0700 Subject: [PATCH 2/4] fix tests --- tests/unit/data/_async/test__mutate_rows.py | 3 ++- tests/unit/data/_async/test_client.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) 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..48a2f6984 100644 --- a/tests/unit/data/_async/test_client.py +++ b/tests/unit/data/_async/test_client.py @@ -1905,11 +1905,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 From bc5a6527da2d74a6ec76f6c645e714537cf4a505 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 26 Oct 2023 16:17:34 -0700 Subject: [PATCH 3/4] added additional checks --- tests/unit/data/_async/test_client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/data/_async/test_client.py b/tests/unit/data/_async/test_client.py index 48a2f6984..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): @@ -2232,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): @@ -2596,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): @@ -2679,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): @@ -2782,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 From 162415f303911525aea74b58ca7d23c999901bbc Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 26 Oct 2023 16:49:04 -0700 Subject: [PATCH 4/4] accept None as retry option --- google/cloud/bigtable_v2/services/bigtable/async_client.py | 4 ++-- google/cloud/bigtable_v2/services/bigtable/client.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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