Skip to content

Commit c4880c3

Browse files
authored
Revert "chore: move retry async check to wrap time (#668)"
This reverts commit 3c69867.
1 parent 0d5ed37 commit c4880c3

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

google/api_core/retry/retry_unary.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ def retry_target(
141141

142142
for sleep in sleep_generator:
143143
try:
144-
return target()
144+
result = target()
145+
if inspect.isawaitable(result):
146+
warnings.warn(_ASYNC_RETRY_WARNING)
147+
return result
145148

146149
# pylint: disable=broad-except
147150
# This function explicitly must deal with broad exceptions.
@@ -277,8 +280,6 @@ def __call__(
277280
Callable: A callable that will invoke ``func`` with retry
278281
behavior.
279282
"""
280-
if inspect.iscoroutinefunction(func):
281-
warnings.warn(_ASYNC_RETRY_WARNING)
282283
if self._on_error is not None:
283284
on_error = self._on_error
284285

tests/unit/retry/test_retry_unary.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,14 @@ def test_retry_target_non_retryable_error(utcnow, sleep):
105105
)
106106
@pytest.mark.asyncio
107107
async def test_retry_target_warning_for_retry(utcnow, sleep):
108-
"""
109-
retry.Retry should raise warning when wrapping an async function.
110-
"""
111-
112-
async def target():
113-
pass # pragma: NO COVER
114-
115-
retry_obj = retry.Retry()
108+
predicate = retry.if_exception_type(ValueError)
109+
target = mock.AsyncMock(spec=["__call__"])
116110

117111
with pytest.warns(Warning) as exc_info:
118-
# raise warning when wrapping an async function
119-
retry_obj(target)
112+
# Note: predicate is just a filler and doesn't affect the test
113+
retry.retry_target(target, predicate, range(10), None)
120114

121-
assert len(exc_info) == 1
115+
assert len(exc_info) == 2
122116
assert str(exc_info[0].message) == retry.retry_unary._ASYNC_RETRY_WARNING
123117
sleep.assert_not_called()
124118

0 commit comments

Comments
 (0)