Skip to content

Commit

Permalink
fix: Retry and timeout values do not propagate in requests during pag…
Browse files Browse the repository at this point in the history
…ination (#518)

* chore: Update gapic-generator-python to v1.18.4

PiperOrigin-RevId: 657207628

Source-Link: googleapis/googleapis@33fe71e

Source-Link: googleapis/googleapis-gen@e02739d
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTAyNzM5ZDEyMmVkMTViZDVlZjU3NzFjNTdmMTJhODNkNDdhMWRkYSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Jul 31, 2024
1 parent 1fef616 commit cbe41fd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ async def sample_list_group_stats():
method=rpc,
request=request,
response=response,
retry=retry,
timeout=timeout,
metadata=metadata,
)

Expand Down Expand Up @@ -570,6 +572,8 @@ async def sample_list_events():
method=rpc,
request=request,
response=response,
retry=retry,
timeout=timeout,
metadata=metadata,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ def sample_list_group_stats():
method=rpc,
request=request,
response=response,
retry=retry,
timeout=timeout,
metadata=metadata,
)

Expand Down Expand Up @@ -977,6 +979,8 @@ def sample_list_events():
method=rpc,
request=request,
response=response,
retry=retry,
timeout=timeout,
metadata=metadata,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from google.api_core import gapic_v1
from google.api_core import retry as retries
from google.api_core import retry_async as retries_async
from typing import (
Any,
AsyncIterator,
Expand All @@ -22,8 +25,18 @@
Tuple,
Optional,
Iterator,
Union,
)

try:
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
OptionalAsyncRetry = Union[
retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None
]
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.Retry, object, None] # type: ignore
OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore

from google.cloud.errorreporting_v1beta1.types import common
from google.cloud.errorreporting_v1beta1.types import error_stats_service

Expand Down Expand Up @@ -52,6 +65,8 @@ def __init__(
request: error_stats_service.ListGroupStatsRequest,
response: error_stats_service.ListGroupStatsResponse,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
):
"""Instantiate the pager.
Expand All @@ -63,12 +78,17 @@ def __init__(
The initial request object.
response (google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse):
The initial response object.
retry (google.api_core.retry.Retry): Designation of what errors,
if any, should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
"""
self._method = method
self._request = error_stats_service.ListGroupStatsRequest(request)
self._response = response
self._retry = retry
self._timeout = timeout
self._metadata = metadata

def __getattr__(self, name: str) -> Any:
Expand All @@ -79,7 +99,12 @@ def pages(self) -> Iterator[error_stats_service.ListGroupStatsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
self._response = self._method(
self._request,
retry=self._retry,
timeout=self._timeout,
metadata=self._metadata,
)
yield self._response

def __iter__(self) -> Iterator[error_stats_service.ErrorGroupStats]:
Expand Down Expand Up @@ -114,6 +139,8 @@ def __init__(
request: error_stats_service.ListGroupStatsRequest,
response: error_stats_service.ListGroupStatsResponse,
*,
retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
):
"""Instantiates the pager.
Expand All @@ -125,12 +152,17 @@ def __init__(
The initial request object.
response (google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse):
The initial response object.
retry (google.api_core.retry.AsyncRetry): Designation of what errors,
if any, should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
"""
self._method = method
self._request = error_stats_service.ListGroupStatsRequest(request)
self._response = response
self._retry = retry
self._timeout = timeout
self._metadata = metadata

def __getattr__(self, name: str) -> Any:
Expand All @@ -141,7 +173,12 @@ async def pages(self) -> AsyncIterator[error_stats_service.ListGroupStatsRespons
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
self._response = await self._method(
self._request,
retry=self._retry,
timeout=self._timeout,
metadata=self._metadata,
)
yield self._response

def __aiter__(self) -> AsyncIterator[error_stats_service.ErrorGroupStats]:
Expand Down Expand Up @@ -180,6 +217,8 @@ def __init__(
request: error_stats_service.ListEventsRequest,
response: error_stats_service.ListEventsResponse,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
):
"""Instantiate the pager.
Expand All @@ -191,12 +230,17 @@ def __init__(
The initial request object.
response (google.cloud.errorreporting_v1beta1.types.ListEventsResponse):
The initial response object.
retry (google.api_core.retry.Retry): Designation of what errors,
if any, should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
"""
self._method = method
self._request = error_stats_service.ListEventsRequest(request)
self._response = response
self._retry = retry
self._timeout = timeout
self._metadata = metadata

def __getattr__(self, name: str) -> Any:
Expand All @@ -207,7 +251,12 @@ def pages(self) -> Iterator[error_stats_service.ListEventsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
self._response = self._method(
self._request,
retry=self._retry,
timeout=self._timeout,
metadata=self._metadata,
)
yield self._response

def __iter__(self) -> Iterator[common.ErrorEvent]:
Expand Down Expand Up @@ -242,6 +291,8 @@ def __init__(
request: error_stats_service.ListEventsRequest,
response: error_stats_service.ListEventsResponse,
*,
retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
):
"""Instantiates the pager.
Expand All @@ -253,12 +304,17 @@ def __init__(
The initial request object.
response (google.cloud.errorreporting_v1beta1.types.ListEventsResponse):
The initial response object.
retry (google.api_core.retry.AsyncRetry): Designation of what errors,
if any, should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
"""
self._method = method
self._request = error_stats_service.ListEventsRequest(request)
self._response = response
self._retry = retry
self._timeout = timeout
self._metadata = metadata

def __getattr__(self, name: str) -> Any:
Expand All @@ -269,7 +325,12 @@ async def pages(self) -> AsyncIterator[error_stats_service.ListEventsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
self._response = await self._method(
self._request,
retry=self._retry,
timeout=self._timeout,
metadata=self._metadata,
)
yield self._response

def __aiter__(self) -> AsyncIterator[common.ErrorEvent]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
from google.api_core import path_template
from google.api_core import retry as retries
from google.auth import credentials as ga_credentials
from google.auth.exceptions import MutualTLSChannelError
from google.cloud.errorreporting_v1beta1.services.error_group_service import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
from google.api_core import path_template
from google.api_core import retry as retries
from google.auth import credentials as ga_credentials
from google.auth.exceptions import MutualTLSChannelError
from google.cloud.errorreporting_v1beta1.services.error_stats_service import (
Expand Down Expand Up @@ -1593,12 +1594,16 @@ def test_list_group_stats_pager(transport_name: str = "grpc"):
)

expected_metadata = ()
retry = retries.Retry()
timeout = 5
expected_metadata = tuple(expected_metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("project_name", ""),)),
)
pager = client.list_group_stats(request={})
pager = client.list_group_stats(request={}, retry=retry, timeout=timeout)

assert pager._metadata == expected_metadata
assert pager._retry == retry
assert pager._timeout == timeout

results = list(pager)
assert len(results) == 6
Expand Down Expand Up @@ -2163,12 +2168,16 @@ def test_list_events_pager(transport_name: str = "grpc"):
)

expected_metadata = ()
retry = retries.Retry()
timeout = 5
expected_metadata = tuple(expected_metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("project_name", ""),)),
)
pager = client.list_events(request={})
pager = client.list_events(request={}, retry=retry, timeout=timeout)

assert pager._metadata == expected_metadata
assert pager._retry == retry
assert pager._timeout == timeout

results = list(pager)
assert len(results) == 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
from google.api_core import path_template
from google.api_core import retry as retries
from google.auth import credentials as ga_credentials
from google.auth.exceptions import MutualTLSChannelError
from google.cloud.errorreporting_v1beta1.services.report_errors_service import (
Expand Down

0 comments on commit cbe41fd

Please sign in to comment.