firebase / firebase/extensions

[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
extension: firestore-bigquery-export type: bug
Dominant language
TypeScript
Stars
979
Forks
433
Avg merge
1d 13h
Merged PRs (30d)
125

Description

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

```ts
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..`.

`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.

```ts
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.

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.