From 7a1e5b204933d64ddb23dad973628cf3833a7a54 Mon Sep 17 00:00:00 2001
From: Chris Wilson <crwilson@google.com>
Date: Wed, 15 Dec 2021 00:10:46 +0000
Subject: [PATCH 1/2] Exclude function target from retry deadline exceeded
 exception message

---
 google/api_core/retry.py | 4 ++--
 tests/unit/test_retry.py | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

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/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"):

From 3b896f8c51b912eec99574eea9754ff724610934 Mon Sep 17 00:00:00 2001
From: Anthonios Partheniou <partheniou@google.com>
Date: Wed, 15 Dec 2021 10:06:16 +0000
Subject: [PATCH 2/2] apply similar patch in retry_async.py

---
 google/api_core/retry_async.py    | 4 ++--
 tests/asyncio/test_retry_async.py | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

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():