Skip to content

Commit 2b7f621

Browse files
authored
fix: Wire up firestore reference in emulated environment. (#72)
1 parent 63c9f54 commit 2b7f621

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/firebase_functions/firestore_fn.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import firebase_functions.core as _core
2727
import cloudevents.http as _ce
2828

29+
from firebase_admin import initialize_app, get_app, _apps, _DEFAULT_APP_NAME
2930
from google.cloud._helpers import _datetime_to_pb_timestamp
3031
from google.cloud.firestore_v1 import _helpers as _firestore_helpers
3132

@@ -115,7 +116,11 @@ def _firestore_endpoint_handler(
115116
"%Y-%m-%dT%H:%M:%S.%f%z",
116117
)
117118

118-
firestore_client = _firestore_v1.Client(database=event_database)
119+
if _DEFAULT_APP_NAME not in _apps:
120+
initialize_app()
121+
app = get_app()
122+
firestore_client = _firestore_v1.Client(project=app.project_id,
123+
database=event_database)
119124
firestore_ref: DocumentReference = firestore_client.document(event_document)
120125
value_snapshot: DocumentSnapshot | None = None
121126
old_value_snapshot: DocumentSnapshot | None = None

0 commit comments

Comments
 (0)