Skip to content

Use async_retry instead of retry in google/cloud/firestore_v1/async_document.py #812

@parthea

Description

@parthea

There is a warning which appears in the Kokoro Prerelease Dependencies presubmit.

E                   UserWarning: Using the synchronous google.api_core.retry.Retry with asynchronous calls may lead to unexpected results. Please use google.api_core.retry_async.AsyncRetry instead.

One potential issue is that retry is used in google/cloud/firestore_v1/async_document.py is used instead of async_retry in google/cloud/firestore_v1/async_document.py

from google.api_core import retry as retries

___________________ test_collections[system-tests-named-db] ____________________

client = 
database = 'system-tests-named-db'

    @pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
    async def test_collections(client, database):
>       collections = [x async for x in client.collections(retry=RETRIES)]

tests/system/test_system_async.py:114: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/system/test_system_async.py:114: in 
    collections = [x async for x in client.collections(retry=RETRIES)]
google/cloud/firestore_v1/async_client.py:306: in collections
    **kwargs,
google/cloud/firestore_v1/services/firestore/async_client.py:1749: in list_collection_ids
    metadata=metadata,
.nox/prerelease_deps-3-7/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py:131: in __call__
    return wrapped_func(*args, **kwargs)
.nox/prerelease_deps-3-7/lib/python3.7/site-packages/google/api_core/retry.py:377: in retry_wrapped_func
    on_error=on_error,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

target = functools.partial(.error_remapped_callable at 0x7f36866069e0>, parent: "projects/...ystem-tests-named-db/documents'), ('x-goog-api-client', 'gl-python/3.7.17 grpc/1.60.0rc1 gax/2.15.0rc1 gapic/2.13.1')])
predicate = .if_exception_type_predicate at 0x7f3685e729e0>
sleep_generator = 
timeout = 60.0, on_error = None, kwargs = {}
deadline = datetime.datetime(2023, 12, 4, 20, 35, 38, 435291), last_exc = None
sleep = 0.06341161243697828
result = 

    def retry_target(
        target, predicate, sleep_generator, timeout=None, on_error=None, **kwargs
    ):
        """Call a function and retry if it fails.
    
        This is the lowest-level retry helper. Generally, you'll use the
        higher-level retry helper :class:`Retry`.
    
        Args:
            target(Callable): The function to call and retry. This must be a
                nullary function - apply arguments with `functools.partial`.
            predicate (Callable[Exception]): A callable used to determine if an
                exception raised by the target should be considered retryable.
                It should return True to retry or False otherwise.
            sleep_generator (Iterable[float]): An infinite iterator that determines
                how long to sleep between retries.
            timeout (float): How long to keep retrying the target.
            on_error (Callable[Exception]): A function to call while processing a
                retryable exception.  Any error raised by this function will *not*
                be caught.
            deadline (float): DEPRECATED: use ``timeout`` instead. For backward
                compatibility, if specified it will override ``timeout`` parameter.
    
        Returns:
            Any: the return value of the target function.
    
        Raises:
            google.api_core.RetryError: If the deadline is exceeded while retrying.
            ValueError: If the sleep generator stops yielding values.
            Exception: If the target raises a method that isn't retryable.
        """
    
        timeout = kwargs.get("deadline", timeout)
    
        if timeout is not None:
            deadline = datetime_helpers.utcnow() + datetime.timedelta(seconds=timeout)
        else:
            deadline = None
    
        last_exc = None
    
        for sleep in sleep_generator:
            try:
                result = target()
                if inspect.isawaitable(result):
>                   warnings.warn(_ASYNC_RETRY_WARNING)
E                   UserWarning: Using the synchronous google.api_core.retry.Retry with asynchronous calls may lead to unexpected results. Please use google.api_core.retry_async.AsyncRetry instead.

.nox/prerelease_deps-3-7/lib/python3.7/site-packages/google/api_core/retry.py:209: UserWarning

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: firestoreIssues related to the googleapis/python-firestore API.type: cleanupAn internal cleanup or hygiene concern.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions