[firestore-bigquery-change-tracker] BigQuery client project override clobbers ADC auto-detection when bqProjectId and PROJECT_ID are both unset

Open Beginner friendly
#3,143 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
cloud, databases

Research direction

Start at src/bigquery/index.ts:146 and compare its client initialization with the fallback used at snapshot.ts:68. Trace how bqProjectId, PROJECT_ID, and GCLOUD_PROJECT are selected, then verify that omitted project settings preserve BigQuery ADC detection while explicit settings still select the intended project.

Written by the indexing model from the issue text.

Description

extension: firestore-bigquery-export type: bug

Package: @firebaseextensions/firestore-bigquery-change-tracker, src/bigquery/index.ts:146 on next.

this.bq = new bigquery.BigQuery();
this.bq.projectId = config.bqProjectId || process.env.PROJECT_ID;

new BigQuery() with no projectId leaves the client's internal {{projectId}} placeholder in place, and @google-cloud/common resolves it from Application Default Credentials on the first request. The assignment on line 146 overwrites that placeholder unconditionally. When the caller passes no bqProjectId and process.env.PROJECT_ID is unset, bq.projectId becomes undefined, auto-detection never runs, and every generated query references undefined.<dataset>.<table>.

PROJECT_ID is an extensions-only variable. A plain Cloud Function (gen1 or gen2) never has it. The Firebase CLI sets FIREBASE_CONFIG and GCLOUD_PROJECT only.

Who is affected: any consumer of the tracker that omits bqProjectId and is not an extension. The firestore-bigquery-export kit is not affected, it always passes bqProjectId (kits/firestore-bigquery-export/src/export-config.ts:191 falls back to projectID.value()). #3120 and 2.2.1 fixed the one kit-reachable variant of this (the update-view path dropped bqProjectId).

Suggested fix: only assign when a value exists, and prefer GCLOUD_PROJECT over PROJECT_ID as the env fallback.

const projectId = config.bqProjectId || process.env.PROJECT_ID || process.env.GCLOUD_PROJECT;
this.bq = projectId ? new bigquery.BigQuery({ projectId }) : new bigquery.BigQuery();

snapshot.ts:68 has the same bqProjectId || process.env.PROJECT_ID fallback and should follow the same order. Both initializeLatestView call sites now pass bqProjectId, so that one is defensive only.

Found during the adversarial review of #3137. Related: #2779 proposes a GOOGLE_CLOUD_PROJECT fallback, which the CLI does not set either.

Dominant language
TypeScript
Stars
979
Forks
433
Avg merge
1d 12h
Merged PRs (30d)
119

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/extensions

All issues in firebase/extensions

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.