firebase / firebase/extensions

🐛 [firestore-bigquery-export] Project ID resolves to undefined in Gen2 / Cloud Run functions

Open
#2,778 3 comments 0 reactions 1 assignee Claimed by @cabljac View on GitHub
reproduced type: bug
Dominant language
TypeScript
Stars
979
Forks
433
Avg merge
1d 13h
Merged PRs (30d)
125

Description

### [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:

```typescript
config.bqProjectId || process.env.PROJECT_ID
```

Two things go wrong in Gen2 / Cloud Run:

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

2. **`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`):

```typescript
config.bqProjectId || process.env.GOOGLE_CLOUD_PROJECT || process.env.PROJECT_ID
```

A PR with this fix is at #2779.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.