[READ] Step 1: Are you in the right place?
Yes β this is a bug in a specific extension in this repository.
[REQUIRED] Step 2: Describe your configuration
- Extension name:
firestore-bigquery-export / package @firebaseextensions/firestore-bigquery-change-tracker
- Extension version:
2.0.2
- Platform: Cloud Functions for Firebase (2nd generation / Cloud Run)
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
Use the firestore-bigquery-change-tracker package inside a Gen2 Cloud Function where bqProjectId is sourced from firebase-functions/params (e.g. projectID.value()).
Observed behavior:
BigQuery queries and table references contain undefined as the project ID:
Table undefined:my_dataset.my_table_raw_changelog
Expected behavior:
The project ID should be correctly resolved from the runtime environment.
Root cause:
Project ID resolution in FirestoreBigQueryEventHistoryTracker and buildLatestSnapshotViewQuery is:
config.bqProjectId || process.env.PROJECT_ID
Two things go wrong in Gen2 / Cloud Run:
-
firebase-functions/params's projectID.value() returns "" when FIREBASE_CONFIG is absent or has no projectId field (common in Gen2). Since "" is falsy in JavaScript, the || falls through.
-
PROJECT_ID is not set in Gen2 / Cloud Run. The standard env var there is GOOGLE_CLOUD_PROJECT, which is never checked. So both sides of the || are falsy and the result is undefined.
Suggested fix:
Add GOOGLE_CLOUD_PROJECT to the fallback chain, consistent with the pattern already used in other extensions in this repo (e.g. delete-user-data):
config.bqProjectId || process.env.GOOGLE_CLOUD_PROJECT || process.env.PROJECT_ID
A PR with this fix is at #2779.
[READ] Step 1: Are you in the right place?
Yes β this is a bug in a specific extension in this repository.
[REQUIRED] Step 2: Describe your configuration
firestore-bigquery-export/ package@firebaseextensions/firestore-bigquery-change-tracker2.0.2[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
Use the
firestore-bigquery-change-trackerpackage inside a Gen2 Cloud Function wherebqProjectIdis sourced fromfirebase-functions/params(e.g.projectID.value()).Observed behavior:
BigQuery queries and table references contain
undefinedas the project ID:Expected behavior:
The project ID should be correctly resolved from the runtime environment.
Root cause:
Project ID resolution in
FirestoreBigQueryEventHistoryTrackerandbuildLatestSnapshotViewQueryis:Two things go wrong in Gen2 / Cloud Run:
firebase-functions/params'sprojectID.value()returns""whenFIREBASE_CONFIGis absent or has noprojectIdfield (common in Gen2). Since""is falsy in JavaScript, the||falls through.PROJECT_IDis not set in Gen2 / Cloud Run. The standard env var there isGOOGLE_CLOUD_PROJECT, which is never checked. So both sides of the||are falsy and the result isundefined.Suggested fix:
Add
GOOGLE_CLOUD_PROJECTto the fallback chain, consistent with the pattern already used in other extensions in this repo (e.g.delete-user-data):A PR with this fix is at #2779.