Skip to content

firestore: Query.stream() raises AttributeError: '_UnaryStreamMultiCallable' object has no attribute '_retry' when a stream on the default retry meets a gRPC error (still present in 2.34.1) #19129

Open

Description

@MikeBSilverman

Environment details

  • google-cloud-firestore 2.34.1 (latest on PyPI)
  • Python 3.12, Linux (Cloud Run, gen2)

What happens

When a stream() that was called with the default retry meets a gRPC error part-way through (we see it as a timeout on a throttled instance), Query.stream calls _retry_query_after_exception(exc, retry, transaction). With retry is gapic_v1.method.DEFAULT, that method reads:

transport = self._client._firestore_api._transport
gapic_callable = transport.run_query
retry = gapic_callable._retry

transport.run_query is the raw gRPC stub (_UnaryStreamMultiCallable), not the wrapped method, so it has no _retry. The caller gets an AttributeError instead of a retry or the original GoogleAPICallError, so except GoogleAPICallError handlers never see the real error.

retry=None fails the same way, at retry._predicate(exc).

Minimal reproduction (no network)

from google.api_core import exceptions, gapic_v1
from google.auth.credentials import AnonymousCredentials
from google.cloud import firestore

client = firestore.Client(project="p", credentials=AnonymousCredentials())
query = client.collection("x")._query()
query._retry_query_after_exception(exceptions.ServiceUnavailable("x"), gapic_v1.method.DEFAULT, None)
# AttributeError: '_UnaryStreamMultiCallable' object has no attribute '_retry'

Workaround

Pass an explicit Retry to every stream() call, e.g. stream(retry=google.api_core.retry.Retry(predicate=lambda exc: False), timeout=...).

Prior report

The same error was reported in googleapis/python-firestore#596 (2022). That issue was closed in 2023 and then reported again by a commenter in January 2024. The repository is now archived, so I'm filing it here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions