firebase-functions-python icon indicating copy to clipboard operation
firebase-functions-python copied to clipboard

Firebase Function with python. Data Are not written to The Firebase Emulator

Open BrightX0 opened this issue 1 year ago • 2 comments

Hi Folks. So I am Having issues Connecting the local firebase emulator with python firebase functions.recently i was trying to migrate my javascript code to python to leverage the python libraries and its ecosystem. If i use a Callable function in javascript to write data to the firebase with firebase Admin privilege it does so, but when i am trying to use with python, The Callable function gets called but if use the firebase Admin package to write data to the firestore the data are not written. is there Anything that I am Missing? MacOS Ventura with Python 3.11 and venv.

BrightX0 avatar Jul 05 '23 15:07 BrightX0

Hey @BrightX0, could you provide a code sample of how you've implemented the function, please?

russellwheatley avatar Jul 10 '23 08:07 russellwheatley

Make sure you have:

from firebase_admin import initialize_app
from firebase_admin.firestore import firestore

initialize_app()
db = firestore.Client(project=GCLOUD_PROJECT)

at the very top.

These two are both vital:

  1. initialize_app is in the docs and you are probably already doing this.
  2. Setting your GCLOUD_PROJECT explicitly is important, you might not be doing this.

When you start the emulator, make sure you use the -p <GCLOUD_PROJECT> arg. The default project name is something like firebase-default-emulator-project. Your default project name in the Python SDK will be plucked from your gcloud environment credentials. In my case, when the project names were mismatched, I'd get a lot of silent "failures" to write data - it was just that the data were being written to the wrong project namespace's default firebase.

EDIT: I should add, I'm using MacOS Monterey and Python 3.11.4 with venv.

ekalosak avatar Sep 11 '23 15:09 ekalosak