Skip to content

Commit 126b5c7

Browse files
authored
chore(revert): Revert "chore: move retry async check to wrap time (#649)" (#667)
This reverts commit ac098a7.
1 parent e031eb5 commit 126b5c7

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
@@ -101,20 +101,14 @@ def test_retry_target_non_retryable_error(utcnow, sleep):
101101
)
102102
@pytest.mark.asyncio
103103
async def test_retry_target_warning_for_retry(utcnow, sleep):
104-
"""
105-
retry.Retry should raise warning when wrapping an async function.
106-
"""
107-
108-
async def target():
109-
pass # pragma: NO COVER
110-
111-
retry_obj = retry.Retry()
104+
predicate = retry.if_exception_type(ValueError)
105+
target = mock.AsyncMock(spec=["__call__"])
112106

113107
with pytest.warns(Warning) as exc_info:
114-
# raise warning when wrapping an async function
115-
retry_obj(target)
108+
# Note: predicate is just a filler and doesn't affect the test
109+
retry.retry_target(target, predicate, range(10), None)
116110

117-
assert len(exc_info) == 1
111+
assert len(exc_info) == 2
118112
assert str(exc_info[0].message) == retry.retry_unary._ASYNC_RETRY_WARNING
119113
sleep.assert_not_called()
120114

0 commit comments

Comments
 (0)