@@ -69,15 +69,22 @@ async def execute(self, initial_state: Any, retry_policy):
6969 self ._strategy .update_state_from_response (response , state )
7070 return
7171 except Exception as e :
72- if not retry_policy ._predicate (e ):
73- raise
72+ # AsyncRetry may expose either 'on_error' (public) or the private
73+ # '_on_error' depending on google.api_core version. Call whichever
74+ # exists so the retry policy can decide to raise (non-retriable /
75+ # deadline exceeded) or allow a retry.
76+ on_error_callable = getattr (retry_policy , "on_error" , None )
77+ if on_error_callable is None :
78+ on_error_callable = getattr (retry_policy , "_on_error" , None )
7479
75- await self ._strategy .recover_state_on_failure (e , state )
80+ if on_error_callable is None :
81+ # No hook available on the policy; re-raise the error.
82+ raise
7683
77- sleep = next (sleep_generator )
78- if deadline is not None and time .monotonic () + sleep > deadline :
79- raise exceptions .RetryError (
80- f"Deadline of { retry_policy ._deadline } s exceeded" , cause = e
81- ) from e
84+ # Let the retry policy handle the error (may raise RetryError).
85+ await on_error_callable (e )
8286
83- await asyncio .sleep (sleep )
87+ # If the retry policy did not raise, allow the strategy to recover
88+ # and then sleep per policy before next attempt.
89+ await self ._strategy .recover_state_on_failure (e , state )
90+ await retry_policy .sleep ()
0 commit comments