File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -486,7 +486,8 @@ def retry_args(options: Optional[HttpRetryOptions]) -> _common.StringDict:
486486 """
487487 if options is None :
488488 return {'stop' : tenacity .stop_after_attempt (1 ), 'reraise' : True }
489-
489+ if options .attempts == 0 :
490+ options .attempts = 1
490491 stop = tenacity .stop_after_attempt (options .attempts or _RETRY_ATTEMPTS )
491492 retriable_codes = options .http_status_codes or _RETRY_HTTP_STATUS_CODES
492493 retry = tenacity .retry_if_exception (
Original file line number Diff line number Diff line change @@ -342,6 +342,33 @@ def test_retries_failed_request_retries_unsuccessfully():
342342 mock_transport .handle_request .assert_called ()
343343
344344
345+ def test_retries_failed_request_no_retries_unsuccessfully ():
346+ mock_transport = mock .Mock (spec = httpx .BaseTransport )
347+ mock_transport .handle_request .side_effect = (
348+ _httpx_response (429 ),
349+ )
350+
351+ client = api_client .BaseApiClient (
352+ vertexai = True ,
353+ project = 'test_project' ,
354+ location = 'global' ,
355+ http_options = _transport_options (
356+ http_options = types .HttpOptions (
357+ retry_options = types .HttpRetryOptions (attempts = 0 )
358+ ),
359+ transport = mock_transport ,
360+ ),
361+ )
362+
363+ with _patch_auth_default ():
364+ try :
365+ client .request (http_method = 'GET' , path = 'path' , request_dict = {})
366+ assert False , 'Expected APIError to be raised.'
367+ except errors .APIError as e :
368+ assert e .code == 429
369+ mock_transport .handle_request .assert_called ()
370+
371+
345372def test_retries_failed_request_retries_unsuccessfully_at_request_level ():
346373 mock_transport = mock .Mock (spec = httpx .BaseTransport )
347374 mock_transport .handle_request .side_effect = (
You can’t perform that action at this time.
0 commit comments