diff --git a/google/api_core/retry.py b/google/api_core/retry.py index bd3a4a65..ce496937 100644 --- a/google/api_core/retry.py +++ b/google/api_core/retry.py @@ -203,8 +203,8 @@ def retry_target(target, predicate, sleep_generator, deadline, on_error=None): if deadline_datetime is not None: if deadline_datetime <= now: raise exceptions.RetryError( - "Deadline of {:.1f}s exceeded while calling {}".format( - deadline, target + "Deadline of {:.1f}s exceeded while calling target function".format( + deadline ), last_exc, ) from last_exc diff --git a/google/api_core/retry_async.py b/google/api_core/retry_async.py index 2dfa2f6e..68a25597 100644 --- a/google/api_core/retry_async.py +++ b/google/api_core/retry_async.py @@ -132,8 +132,8 @@ async def retry_target(target, predicate, sleep_generator, deadline, on_error=No # Chains the raising RetryError with the root cause error, # which helps observability and debugability. raise exceptions.RetryError( - "Deadline of {:.1f}s exceeded while calling {}".format( - deadline, target + "Deadline of {:.1f}s exceeded while calling target function".format( + deadline ), last_exc, ) from last_exc diff --git a/tests/asyncio/test_retry_async.py b/tests/asyncio/test_retry_async.py index 9e51044b..873caaf1 100644 --- a/tests/asyncio/test_retry_async.py +++ b/tests/asyncio/test_retry_async.py @@ -120,6 +120,10 @@ async def test_retry_target_deadline_exceeded(utcnow, sleep): assert exc_info.match("last exception: meep") assert target.call_count == 2 + # Ensure the exception message does not include the target fn: + # it may be a partial with user data embedded + assert str(target) not in exc_info.exconly() + @pytest.mark.asyncio async def test_retry_target_bad_sleep_generator(): diff --git a/tests/unit/test_retry.py b/tests/unit/test_retry.py index 199ca559..74c5d77c 100644 --- a/tests/unit/test_retry.py +++ b/tests/unit/test_retry.py @@ -152,6 +152,10 @@ def test_retry_target_deadline_exceeded(utcnow, sleep): assert exc_info.match("last exception: meep") assert target.call_count == 2 + # Ensure the exception message does not include the target fn: + # it may be a partial with user data embedded + assert str(target) not in exc_info.exconly() + def test_retry_target_bad_sleep_generator(): with pytest.raises(ValueError, match="Sleep generator"):