Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Emulator support broken since 2.1.0 at least on Windows #359

@lietu

Description

@lietu

Environment details

  • OS type and version: Windows 10 20H2 build 19042.867
  • Python version: 3.9.1
  • pip version: 21.0.1
  • google-cloud-firestore version: 2.1.0 - 2.1.1 at least are affected

Steps to reproduce

  1. pip install google-cloud-firestore in e.g. a virtualenv
  2. Run emulator via gcloud beta emulators firestore start --host-port=127.0.0.1:8686
  3. Set FIRESTORE_EMULATOR_HOST=127.0.0.1:8686 environment variable
  4. Run your code
  5. Crash with failed to connect to all addresses on first database access

Crashes near instantly if you use the async client but synchronous client gets it after some lengthy timeout.

If you run this exact same code but pip install google-cloud-firestore==1.9.0, it works perfectly. ==2.0.0 crashes because GOOGLE_APPLICATION_CREDENTIALS is not set? 2.0.1 works, 2.0.2 works.

I tried the myriad of other FIREBASE_FIRESTORE_EMULATOR_ADDRESS etc. and none of them seemed to resolve anything, and the documentation nor the code does not seem to support that this should be necessary. I also tried running the emulator via firebase emulators:start --only firestore but that seemed to be just a downgrade without solving any problems - it didn't allow me to set the port without some configuration file.

The emulator logs show no connection attempts or other issues from the broken client versions.

Code example

Your own example code modified just to work with an emulator in general:

from os import environ
from unittest.mock import Mock

import google.auth.credentials
from google.cloud import firestore


def get_db() -> firestore.Client:
    if environ.get("FIRESTORE_EMULATOR_HOST"):
        print("Connecting to emulator")
        return firestore.Client(
            project="firestore-test",
            credentials=Mock(spec=google.auth.credentials.Credentials),
        )
    else:
        print("Connecting to live environment")
        return firestore.Client()


db = get_db()

# Add a new document
print("Creating document")
doc_ref = db.collection(u'users').document(u'alovelace')
doc_ref.set({  # Crash
    u'first': u'Ada',
    u'last': u'Lovelace',
    u'born': 1815
})

# Then query for documents
print("Reading documents")
users_ref = db.collection(u'users')

for doc in users_ref.stream():
    print(u'{} => {}'.format(doc.id, doc.to_dict()))

Stack trace

From ==2.1.1

Traceback (most recent call last):
  File "C:\source\gcf\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 67, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\source\gcf\venv\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\source\gcf\venv\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses"
        debug_error_string = "{"created":"@1621761335.758000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3009,"referenced_errors":[{"created":"@1621761320.831000000","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":398,"grpc_status":14}]}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\source\gcf\venv\lib\site-packages\google\api_core\retry.py", line 188, in retry_target
    return target()
  File "C:\source\gcf\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 69, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\source\gcf\main.py", line 25, in <module>
    doc_ref.set({
  File "C:\source\gcf\venv\lib\site-packages\google\cloud\firestore_v1\document.py", line 167, in set
    write_results = batch.commit(**kwargs)
  File "C:\source\gcf\venv\lib\site-packages\google\cloud\firestore_v1\batch.py", line 57, in commit
    commit_response = self._client._firestore_api.commit(
  File "C:\source\gcf\venv\lib\site-packages\google\cloud\firestore_v1\services\firestore\client.py", line 836, in commit
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "C:\source\gcf\venv\lib\site-packages\google\api_core\gapic_v1\method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\source\gcf\venv\lib\site-packages\google\api_core\retry.py", line 285, in retry_wrapped_func
    return retry_target(
  File "C:\source\gcf\venv\lib\site-packages\google\api_core\retry.py", line 203, in retry_target
    six.raise_from(
  File "<string>", line 3, in raise_from
google.api_core.exceptions.RetryError: Deadline of 60.0s exceeded while calling functools.partial(<function _wrap_unary_errors.<locals>.error_remapped_callable at 0x000001DFD2A20430>, database: "projects/firestore-test/databases/(default)"
writes {
  update {
    name: "projects/firestore-test/databases/(default)/documents/users/alovelace"
    fields {
      key: "born"
      value {
        integer_value: 1815
      }
    }
    fields {
      key: "first"
      value {
        string_value: "Ada"
      }
    }
    fields {
      key: "last"
      value {
        string_value: "Lovelace"
      }
    }
  }
}
, metadata=[('google-cloud-resource-prefix', 'projects/firestore-test/databases/(default)'), ('authorization', 'Bearer owner'), ('x-goog-request-params', 'database=projects/firestore-test/databases/%28default%29'), ('x-goog-api-client', 'gl-python/3.9.1 grpc/1.38.0 gax/1.28.0 gapic/2.1.1')]), last exception: 503 failed to connect to all addresses

Metadata

Metadata

Labels

🚨This issue needs some love.api: firestoreIssues related to the googleapis/python-firestore API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions