Skip to content

Commit 34ebdcc

Browse files
sushicwparthea
andauthored
fix: exclude function target from retry deadline exceeded exception message (googleapis#318)
* Exclude function target from retry deadline exceeded exception message * apply similar patch in retry_async.py Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent cc46aa6 commit 34ebdcc

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

google/api_core/retry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def retry_target(target, predicate, sleep_generator, deadline, on_error=None):
203203
if deadline_datetime is not None:
204204
if deadline_datetime <= now:
205205
raise exceptions.RetryError(
206-
"Deadline of {:.1f}s exceeded while calling {}".format(
207-
deadline, target
206+
"Deadline of {:.1f}s exceeded while calling target function".format(
207+
deadline
208208
),
209209
last_exc,
210210
) from last_exc

google/api_core/retry_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ async def retry_target(target, predicate, sleep_generator, deadline, on_error=No
132132
# Chains the raising RetryError with the root cause error,
133133
# which helps observability and debugability.
134134
raise exceptions.RetryError(
135-
"Deadline of {:.1f}s exceeded while calling {}".format(
136-
deadline, target
135+
"Deadline of {:.1f}s exceeded while calling target function".format(
136+
deadline
137137
),
138138
last_exc,
139139
) from last_exc

tests/asyncio/test_retry_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ async def test_retry_target_deadline_exceeded(utcnow, sleep):
120120
assert exc_info.match("last exception: meep")
121121
assert target.call_count == 2
122122

123+
# Ensure the exception message does not include the target fn:
124+
# it may be a partial with user data embedded
125+
assert str(target) not in exc_info.exconly()
126+
123127

124128
@pytest.mark.asyncio
125129
async def test_retry_target_bad_sleep_generator():

tests/unit/test_retry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def test_retry_target_deadline_exceeded(utcnow, sleep):
152152
assert exc_info.match("last exception: meep")
153153
assert target.call_count == 2
154154

155+
# Ensure the exception message does not include the target fn:
156+
# it may be a partial with user data embedded
157+
assert str(target) not in exc_info.exconly()
158+
155159

156160
def test_retry_target_bad_sleep_generator():
157161
with pytest.raises(ValueError, match="Sleep generator"):

0 commit comments

Comments
 (0)