Skip to content

fix(bigquery): preserve project on view updates - #3121

Closed
CorieW wants to merge 1 commit into
kitsfrom
fix/kits-bigquery-project-id
Closed

fix(bigquery): preserve project on view updates#3121
CorieW wants to merge 1 commit into
kitsfrom
fix/kits-bigquery-project-id

Conversation

@CorieW

@CorieW CorieW commented Sep 7, 2026

Copy link
Copy Markdown
Member

Changes

  • Pass the BigQuery client's project ID when regenerating an existing snapshot view.
  • Add regression coverage proving the configured BigQuery project wins over the function runtime project.

Testing

  • npm run compile
  • jest --runInBand src/__tests__/bigquery/materializedViews/initializeLatestView.test.ts

Closes #3120

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the initializeLatestView function to pass the BigQuery project ID (bqProjectId) when initializing or updating the latest view, ensuring the correct project is referenced instead of defaulting to the function's project ID. A corresponding unit test has been added to verify this behavior. There are no review comments, so no further feedback is provided.

@IzaakGough IzaakGough left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks right. The update path was the last place still falling back to process.env.PROJECT_ID, and since bq.projectId is set to config.bqProjectId || process.env.PROJECT_ID it can't be worse than before. I checked out the head and confirmed the new test fails without the added line.

One thing to flag: firestore-bigquery-change-tracker is published separately and is still on 2.0.4, which is what functions/package.json resolves via ^2.0.4, so deployed instances won't pick this up until a new version goes out. Happy for that to be a follow-up if releases are batched here, just wanted to make sure it isn't missed.

@ajperel

ajperel commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Is there a larger problem for kits here that all process.env.PROJECT_ID uses won't work? There were a bunch of them: https://github.com/search?q=repo%3Afirebase%2Fextensions+process.env.PROJECT_ID&type=code

I haven't tested a deployed function but from documentation I assume GCLOUD_PROJECT and GOOGLE_CLOUD_PROJECT will be populated alternatives.

cabljac added a commit that referenced this pull request Sep 7, 2026
…view updates, release 2.2.1 (#3137)

Cherry-pick of da21982 from #3121 (Corie's fix, approved by Izaak) onto
`next`, plus the 2.2.1 version bump and changelog entry. #3121 targets
`kits`, but the tracker is published from `next`, so the fix never
reached npm from there.

The bug: `initializeLatestView` builds the snapshot query for an
existing `_raw_latest` view without `bqProjectId`, so
`buildLatestSnapshotViewQuery` falls back to `process.env.PROJECT_ID`.
That variable is only set for extensions. On a kit the view query became
`undefined.<dataset>.<table>` and the `initBigQuerySync` task failed in
`afterFirstDeploy`. The create path already passed the project. The fix
passes `bq.projectId` on the update path too, matching the create path.

Tests: the materializedViews suites pass locally (20 tests), including
the new one that sets `process.env.PROJECT_ID` to a decoy and asserts
the query uses the BigQuery project. Not verified against a live
redeploy.

After merge, dispatch `npm_publish_bq_scripts.yml` for 2.2.1, then
regenerate the kit shrinkwrap in the stack so the rc pins it.

Fixes #3120

---------

Co-authored-by: Corie Watson <watson.corie@gmail.com>
@cabljac

cabljac commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Superseded by #3137, which cherry-picked this commit (da21982, author preserved) onto next and shipped it as tracker 2.2.1. This PR targeted kits, but the tracker publishes from next, so the fix had to land there to reach npm. 2.2.1 is now on npm and the kit stack (#3127) pins it. Thanks Corie.

@cabljac cabljac closed this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [@firebase-function-kits/firestore-bigquery-export] afterFirstDeploy taskqueue initialization failed from missing PROJECT_ID

4 participants