fix(firestore-bigquery-change-tracker): resolve project ID from GOOGLE_CLOUD_PROJECT for Gen2 functions#2779
Conversation
…E_CLOUD_PROJECT for Gen2 functions PROJECT_ID is only set in Gen1 Cloud Functions. Gen2 functions running on Cloud Run expose GOOGLE_CLOUD_PROJECT instead, causing project ID to resolve to undefined and producing broken SQL (undefined.dataset.table). Adds a small gcpProject utility that mirrors the GOOGLE_CLOUD_PROJECT || PROJECT_ID fallback pattern already used in other extensions (delete-user-data). Fixes firebase#2778 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces a utility function resolveGcpProjectIdForBigQuery to standardize Google Cloud Project ID resolution, prioritizing explicit configuration over environment variables. The changes update the FirestoreBigQueryEventHistoryTracker and snapshot query builder to use this utility. Feedback recommends adding error handling for unresolved project IDs to prevent invalid SQL generation and removing redundant logic in the resolution function.
|
Hi @davestimpert do you mind signing the Google CLA agreement? you can click on the CI run it should link you to the form |
…edback - Remove redundant `|| undefined` in resolveGcpProjectIdForBigQuery - Throw a descriptive error in buildLatestSnapshotViewQuery when project ID cannot be resolved, preventing silent generation of invalid SQL Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Fixes project ID resolving to
undefinedin Gen2 / Cloud Run environments, producing broken SQL likeTable undefined:dataset.table.Root cause — two compounding issues in Gen2:
firebase-functions/params'sprojectID.value()returns""whenFIREBASE_CONFIGlacksprojectId. Since""is falsy,config.bqProjectId || process.env.PROJECT_IDfalls through even when a project ID was explicitly passed.PROJECT_IDis not set in Gen2 / Cloud Run — the standard env var there isGOOGLE_CLOUD_PROJECT, which was never checked.Fix: add
GOOGLE_CLOUD_PROJECTto the fallback chain, matching the pattern already used in this repo (e.g.delete-user-data):Fixes #2778
Changes
src/bigquery/gcpProject.ts— new utilityresolveGcpProjectIdForBigQuery(preferred?)src/bigquery/index.ts— use utility when settingbq.projectIdsrc/bigquery/snapshot.ts— use utility inbuildLatestSnapshotViewQuerysrc/__tests__/bigquery/gcpProject.test.ts— unit tests covering the fallback priority orderTest plan
resolveGcpProjectIdForBigQueryunit tests pass (npm test -- gcpProject)npm test -- snapshot)🤖 Generated with Claude Code