Repository navigation
Closed
Description
[REQUIRED] Environment info
firebase-tools: 12.4.7
Platform: Windows
[REQUIRED] Test case
When I try to deploy a triggered Python, 2nd-gen cloud function, it fails with a database not found error.
[REQUIRED] Steps to reproduce
- Create a function in your main.py:
@firestore_fn.on_document_created(document='a/{aId}/b/{bId}')
def do_magic(event: Event[DocumentSnapshot]) -> None:
"""
Do magic
"""
return None- Run
firebase deployon the function.
[REQUIRED] Expected behavior
Deploys succeeds.
[REQUIRED] Actual behavior
Deploy fails with the following message:
=== Deploying to 'propio-app'...
i deploying functions
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
+ functions: required API cloudfunctions.googleapis.com is enabled
+ functions: required API cloudbuild.googleapis.com is enabled
+ artifactregistry: required API artifactregistry.googleapis.com is enabled
i functions: Loading and analyzing source code for codebase default to determine what to deploy
* Serving Flask app 'serving'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:8081
Press CTRL+C to quit
127.0.0.1 - - [15/Sep/2023 13:13:27] "GET /__/functions.yaml HTTP/1.1" 200 -
2023-09-15 13:13:27,719 - werkzeug - INFO - 127.0.0.1 - - [15/Sep/2023 13:13:27] "GET /__/functions.yaml HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2023 13:13:27] "GET /__/quitquitquit HTTP/1.1" 200 -
2023-09-15 13:13:27,728 - werkzeug - INFO - 127.0.0.1 - - [15/Sep/2023 13:13:27] "GET /__/quitquitquit HTTP/1.1" 200 -
i functions: preparing functions directory for uploading...
i functions: packaged C:\src\propio3\webapp\backend\functions (40.74 KB) for uploading
There was an error retrieving the Firestore database. Currently, the database id is set to (default), make sure it exists.
Error: Failed to make request to http://127.0.0.1:8080/v1/projects/propio-app/databases/(default)
Reacted by Alwan Nuha
Activity
dominoFire commentedon Sep 15, 2023
Please help me diagnosing this issue. I'm blocked on writing trigger cloud functions and I don't want to default to HTTPs functions.
This issue also happens in firebase-tools 12.5.4
[-]Cloud Function deploy fails [/-][+]Cloud Function deploy fails for Firestore-triggered function[/+]aalej commentedon Sep 19, 2023
Hi @dominoFire, thanks for reaching out and for providing a detailed report. I tried to reproduce the behavior you mentioned, but I encountered no errors when trying to deploy the code snippet you provided.
One thing I noticed is that in your debug logs, it makes a request to
GET http://127.0.0.1:8080/v1/projects/<project_id>/databases/(default). I tried comparing this to my debug logs, and mine showsGET https://firestore.googleapis.com/v1/projects/<project_id>/databases/(default).Could you provide additional information such as your
firebase.jsonfile or if you’re setting any environment variables during/before deploying? Please remove any PII (personal identifiable information) before sharing the file.joehan commentedon Sep 19, 2023
Specifically, could you check that the
FIRESTORE_EMULATOR_HOSTandFIRESTORE_URLenvironment vairables are not set? Looking through the provided debug logs, it seems like one of them must be set & that is causing your requests to go to the wrong host.jjgriff93 commentedon Sep 25, 2023
Getting this now as well after upgrading from a Firestore v1 trigger to v2
google-oss-bot commentedon Oct 4, 2023
Hey @dominoFire. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
landa commentedon Oct 4, 2023
I was getting the same error and it was fixed after unsetting @joehan's environment variables:
It seems that this is a bug in the Firebase CLI as using the emulators shouldn't interfere with deploying.
dominoFire commentedon Oct 6, 2023
Yeah, somehow I added the envvars. I haven't tested yet without the envvars, but this seems to be the error root cause. Thanks all!
joehan commentedon Oct 10, 2023
Glad that this fixed your issues! I suspect there is a minor underlying issue here - during functions deployment, we try to get the default database(https://github.com/firebase/firebase-tools/blob/master/src/deploy/functions/services/firestore.ts#L12) using getDatabase, which uses an API client that calls firestoreOriginOrEmulator (https://github.com/firebase/firebase-tools/blob/master/src/gcp/firestore.ts#L8)
I suspect we can prevent this issue by just switching that to firestoreOrigin, but we ought to double check that doing so won't break the emualtor anywhere. @blidd-google do you mind taking a pass through the usage of the firestore functions in that file and sending a PR to switch it over if this is safe?
LouisBensard commentedon Dec 7, 2023
Hello, I'm running into a similar issue. I've never user the emulator but my functions seem to deploy only on the development environment (see warning in code below). See below the result of the firebase deploy --only functions command:
(After this the functions proceed to deploy)
I have tried unsetting my environment variables, similar to suggested by @landa but no success. This is how I tried to unset them:
I am using 2nd Gen cloud function, written in python. Deployment via the default (apparently dev server) has been successful without issue.
EDIT: I gave up and moved my Python 2nd Gen functions to Typescript 1st Gen as it doesn't have the 'development environment warning' issue. Hopefully the 2nd Gen functions get fixed.
hasnainv commentedon Jan 2, 2024
@Genev-a I'm running into the same issue and I do not have any FIRESTORE_* environment variable set.
segunak commentedon Jan 15, 2024
Same issue here. Python Gen 2, no FIRESTORE_* environment variables set. Any attempts to use
firebase deployend with failure and a warning that the development server is being used.LouisBensard commentedon Jan 15, 2024
@hasnainv @segunak I gave up using Gen 2 function in Python and reverted back to using 1st gen functions written in Typescript. Even aside from this unresolved issue, the documentation online is more robust for the tried and tested 1st gen functions. Good luck!
david-shortman commentedon Mar 23, 2024
I'm also getting this issue for the first time specifically when migrating database triggered functions to v2. I've successfully migrated other HTTP triggered v1 functions to v2.
david-shortman commentedon Mar 23, 2024
In my case, I needed to add another role to my deployment service agent that allowed reading Cloud Datastore, which is apparently used by v2 database triggered functions.
jimmy0251 commentedon Jul 3, 2024
This worked for me as well. I had to add "Cloud Datastore Viewer" role to be specific. I think error message can be improved here.