Skip to content

πŸ› [firestore-bigquery-export] Project ID resolves to undefined in Gen2 / Cloud Run functionsΒ #2778

@davestimpert

Description

@davestimpert

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

  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):

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

A PR with this fix is at #2779.

Metadata

Metadata

Assignees

Labels

type: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions