Skip to content

Commit

Permalink
fix: exclude function target from retry deadline exceeded exception m…
Browse files Browse the repository at this point in the history
…essage (#318)

* Exclude function target from retry deadline exceeded exception message

* apply similar patch in retry_async.py

Co-authored-by: Anthonios Partheniou <[email protected]>
  • Loading branch information
sushicw and parthea authored Dec 15, 2021
1 parent cc46aa6 commit 34ebdcc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions google/api_core/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions google/api_core/retry_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/asyncio/test_retry_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit 34ebdcc

Please sign in to comment.