Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirestoreAsyncClient and FirestoreClient doesnt support gcloud emulators firestore #727

Closed
ben-marengo-msmg opened this issue Jun 20, 2023 · 1 comment
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: question Request for information or clarification. Not an issue.

Comments

@ben-marengo-msmg
Copy link

Environment details

  • OS type and version: macos 13.4 (22F66)
  • Python version: 3.11.0
  • pip version: pip 22.3.1
  • google-cloud-firestore version: 2.10.0

Steps to reproduce

  1. run code below
  2. get error

Code example

docker run --rm -d -p 8090:8090 --name firestore-emulator google/cloud-sdk:emulators gcloud emulators firestore start --host-port=0.0.0.0:8090
import asyncio
import os

from google.cloud.firestore_v1.services.firestore import FirestoreAsyncClient
from google.cloud.firestore_v1.types import Write, Document, Value, BatchWriteRequest


async def main():
    fs_client = FirestoreAsyncClient()

    _batch = [
        Write(
            update=Document(
                name=f"projects/dummy-project/databases/(default)/documents/my_collection/abc",
                fields={
                    "rpt": Value(double_value=123.456)
                },
            )
        ),
        Write(
            update=Document(
                name=f"projects/dummy-project/databases/(default)/documents/my_collection/def",
                fields={
                    "rpt": Value(double_value=456.789)
                },
            )
        )
    ]

    response = await fs_client.batch_write(request=BatchWriteRequest(
        database="projects/dummy-project/databases/(default)",
        writes=_batch
    ))

    print(response)


if __name__ == "__main__":
    os.environ["FIRESTORE_EMULATOR_HOST"] = "localhost:8090"
    asyncio.run(main())

Stack trace

/Users/ben.marengo/code/pyenvs/scratch311/bin/python /Users/ben.marengo/code/scratch/bq_to_firestore/with_fs_async_client.py 
Traceback (most recent call last):
  File "/Users/ben.marengo/code/pyenvs/scratch311/lib/python3.11/site-packages/google/api_core/grpc_helpers_async.py", line 81, in __await__
    response = yield from self._call.__await__()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ben.marengo/code/pyenvs/scratch311/lib/python3.11/site-packages/grpc/aio/_call.py", line 290, in __await__
    raise _create_rpc_error(self._cython_call._initial_metadata,
grpc.aio._call.AioRpcError: <AioRpcError of RPC that terminated with:
	status = StatusCode.PERMISSION_DENIED
	details = "Permission denied on resource project dummy-project."
	debug_error_string = "UNKNOWN:Error received from peer ipv4:142.250.200.10:443 {grpc_message:"Permission denied on resource project dummy-project.", grpc_status:7, created_time:"2023-06-20T14:51:51.60572+01:00"}"
>

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

Traceback (most recent call last):
  File "/Users/ben.marengo/code/scratch/bq_to_firestore/with_fs_async_client.py", line 40, in <module>
    asyncio.run(main())
  File "/Users/ben.marengo/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/ben.marengo/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ben.marengo/.pyenv/versions/3.11.0/lib/python3.11/asyncio/base_events.py", line 650, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/ben.marengo/code/scratch/bq_to_firestore/with_fs_async_client.py", line 30, in main
    response = await fs_client.batch_write(request=BatchWriteRequest(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ben.marengo/code/pyenvs/scratch311/lib/python3.11/site-packages/google/cloud/firestore_v1/services/firestore/async_client.py", line 1847, in batch_write
    response = await rpc(
               ^^^^^^^^^^
  File "/Users/ben.marengo/code/pyenvs/scratch311/lib/python3.11/site-packages/google/api_core/grpc_helpers_async.py", line 84, in __await__
    raise exceptions.from_grpc_error(rpc_error) from rpc_error
google.api_core.exceptions.PermissionDenied: 403 Permission denied on resource project dummy-project. [links {
  description: "Google developer console API key"
  url: "https://console.developers.google.com/project/dummy-project/apiui/credential"
}
, reason: "CONSUMER_INVALID"
domain: "googleapis.com"
metadata {
  key: "service"
  value: "firestore.googleapis.com"
}
metadata {
  key: "consumer"
  value: "projects/dummy-project"
}
]

Process finished with exit code 1
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Jun 20, 2023
@meredithslota
Copy link
Contributor

Emulator support was added in #269 (circa 2020). The problem appears to be a permissions error with the project you're using, or it's possible that the emulator is not setup correctly. Can you verify that you've run the emulator configuration steps here? https://firebase.google.com/docs/emulator-suite/connect_firestore and https://firebase.google.com/docs/emulator-suite/install_and_configure

This discussion also includes options for authentication: https://groups.google.com/g/firebase-talk/c/IKo6PsXMqlQ

@meredithslota meredithslota added the type: question Request for information or clarification. Not an issue. label Aug 16, 2023
@meredithslota meredithslota self-assigned this Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants