From 439605a59f4688ba8e318050becc89595aaf4a7a Mon Sep 17 00:00:00 2001 From: omair Date: Thu, 26 Oct 2023 01:06:00 +0000 Subject: [PATCH] fix: add warning to retry_target to avoid incorrect usage --- google/api_core/retry.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/google/api_core/retry.py b/google/api_core/retry.py index 84b5d0fe7..49ed2544e 100644 --- a/google/api_core/retry.py +++ b/google/api_core/retry.py @@ -62,6 +62,7 @@ def check_if_exists(): import random import sys import time +import inspect from typing import Any, Callable, TypeVar, TYPE_CHECKING import requests.exceptions @@ -201,7 +202,10 @@ def retry_target( for sleep in sleep_generator: try: - return target() + result = target() + if inspect.isawaitable(result): + raise exceptions.GoogleAPIError("Warning: Use google.api_core.retry_async.AsyncRetry for async calls!") + return result # pylint: disable=broad-except # This function explicitly must deal with broad exceptions.