Support multiple errors (#10376)

in on_retry
This commit is contained in:
William FH 2023-09-08 09:07:15 -07:00 committed by GitHub
parent 2423f7f3b4
commit 1b0eebe1e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -254,7 +254,7 @@ class Runnable(Generic[Input, Output], ABC):
def with_retry( def with_retry(
self, self,
*, *,
retry_if_exception_type: Tuple[Type[BaseException]] = (Exception,), retry_if_exception_type: Tuple[Type[BaseException], ...] = (Exception,),
wait_exponential_jitter: bool = True, wait_exponential_jitter: bool = True,
stop_after_attempt: int = 3, stop_after_attempt: int = 3,
) -> Runnable[Input, Output]: ) -> Runnable[Input, Output]:
@ -280,7 +280,7 @@ class Runnable(Generic[Input, Output], ABC):
self, self,
fallbacks: Sequence[Runnable[Input, Output]], fallbacks: Sequence[Runnable[Input, Output]],
*, *,
exceptions_to_handle: Tuple[Type[BaseException]] = (Exception,), exceptions_to_handle: Tuple[Type[BaseException], ...] = (Exception,),
) -> RunnableWithFallbacks[Input, Output]: ) -> RunnableWithFallbacks[Input, Output]:
return RunnableWithFallbacks( return RunnableWithFallbacks(
runnable=self, runnable=self,
@ -653,7 +653,7 @@ class RunnableWithFallbacks(Serializable, Runnable[Input, Output]):
runnable: Runnable[Input, Output] runnable: Runnable[Input, Output]
fallbacks: Sequence[Runnable[Input, Output]] fallbacks: Sequence[Runnable[Input, Output]]
exceptions_to_handle: Tuple[Type[BaseException]] = (Exception,) exceptions_to_handle: Tuple[Type[BaseException], ...] = (Exception,)
class Config: class Config:
arbitrary_types_allowed = True arbitrary_types_allowed = True

View File

@ -24,7 +24,7 @@ U = TypeVar("U")
class RunnableRetry(RunnableBinding[Input, Output]): class RunnableRetry(RunnableBinding[Input, Output]):
"""Retry a Runnable if it fails.""" """Retry a Runnable if it fails."""
retry_exception_types: Tuple[Type[BaseException]] = (Exception,) retry_exception_types: Tuple[Type[BaseException], ...] = (Exception,)
wait_exponential_jitter: bool = True wait_exponential_jitter: bool = True

View File

@ -1507,7 +1507,7 @@ async def test_async_retrying(mocker: MockerFixture) -> None:
with pytest.raises(ValueError): with pytest.raises(ValueError):
await runnable.with_retry( await runnable.with_retry(
stop_after_attempt=2, stop_after_attempt=2,
retry_if_exception_type=(ValueError,), retry_if_exception_type=(ValueError, KeyError),
).ainvoke(1) ).ainvoke(1)
assert _lambda_mock.call_count == 2 # retried assert _lambda_mock.call_count == 2 # retried