Skip to content

fix(firestore): allow uninitialized client references in pipeline sources - #9318

Merged
wu-hui merged 2 commits into
mainfrom
fix-pipeline-reference-validation
Sep 14, 2026
Merged

wu-hui merged 2 commits into
mainfrom
fix-pipeline-reference-validation

Conversation

@wu-hui

@wu-hui wu-hui commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #9186

Problem

When DocumentReference or CollectionReference instances are passed to firestore.pipeline().documents(...) or firestore.pipeline().collection(...), PipelineSource._validateReference() accessed this.db.formattedName and reference.firestore.formattedName.

formattedName synchronously evaluates this.projectId, which throws:

Error: INTERNAL ERROR: Client is not yet ready to issue requests.

when the Firestore client was created without an explicit projectId (e.g., standard Google Cloud auto-detection via ADC/metadata server) before asynchronous lazy initialization (initializeIfNeeded()) has occurred.

Solution

  1. In PipelineSource._validateReference():
    • Fast path: If reference.firestore === this.db, return true immediately without inspecting formattedName. References created from the same client instance always belong to the same database.
    • Cross-instance validation: Safely inspect _projectId and databaseId without triggering premature synchronous initialization.
  2. Added comprehensive unit tests in dev/test/pipelines/pipeline.ts verifying uninitialized client support for single references, lists of references, options objects, and mixed string/reference arrays, as well as proper rejection of cross-database references.
  3. Added end-to-end backend system tests in dev/system-test/pipeline.ts verifying that pipelines constructed with references from uninitialized clients compile, execute, and successfully retrieve documents from the live backend.

@wu-hui
wu-hui requested a review from a team as a code owner September 14, 2026 14:48
@product-auto-label product-auto-label Bot added the api: firestore Issues related to the Firestore API. label Sep 14, 2026

@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 pipeline reference validation to support uninitialized Firestore instances by safely constructing the database name when the project ID is missing, and adds an early-exit identity check. It also includes comprehensive unit and system tests to verify this behavior. The feedback suggests changing the early return in the validation helper from return true; to return; to maintain a consistent void return type.

Comment on lines +294 to +296
if (reference.firestore === this.db) {
return true;
}

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.

medium

The _validateReference method is a validation helper that throws an error on failure and otherwise returns void (implicitly undefined). Returning true in the fast-path check (reference.firestore === this.db) introduces an inconsistent return type, as the rest of the function does not return a value. It is cleaner and more idiomatic to simply use return; to exit early.

Suggested change
if (reference.firestore === this.db) {
return true;
}
if (reference.firestore === this.db) {
return;
}

@wu-hui
wu-hui force-pushed the fix-pipeline-reference-validation branch from 7fde20a to 3bfbbfd Compare September 14, 2026 14:57
@dlarocque dlarocque assigned wu-hui and unassigned dlarocque Sep 14, 2026
@wu-hui
wu-hui merged commit 435bcae into main Sep 14, 2026
50 checks passed
@wu-hui
wu-hui deleted the fix-pipeline-reference-validation branch September 14, 2026 18:27
thiyaguk09 pushed a commit to thiyaguk09/google-cloud-node-fork that referenced this pull request Sep 15, 2026
…rces (googleapis#9318)

Fixes googleapis#9186

### Problem
When `DocumentReference` or `CollectionReference` instances are passed
to `firestore.pipeline().documents(...)` or
`firestore.pipeline().collection(...)`,
`PipelineSource._validateReference()` accessed `this.db.formattedName`
and `reference.firestore.formattedName`.

`formattedName` synchronously evaluates `this.projectId`, which throws:
```
Error: INTERNAL ERROR: Client is not yet ready to issue requests.
```
when the Firestore client was created without an explicit `projectId`
(e.g., standard Google Cloud auto-detection via ADC/metadata server)
before asynchronous lazy initialization (`initializeIfNeeded()`) has
occurred.

### Solution
1. In `PipelineSource._validateReference()`:
- Fast path: If `reference.firestore === this.db`, return `true`
immediately without inspecting `formattedName`. References created from
the same client instance always belong to the same database.
- Cross-instance validation: Safely inspect `_projectId` and
`databaseId` without triggering premature synchronous initialization.
2. Added comprehensive unit tests in `dev/test/pipelines/pipeline.ts`
verifying uninitialized client support for single references, lists of
references, options objects, and mixed string/reference arrays, as well
as proper rejection of cross-database references.
3. Added end-to-end backend system tests in
`dev/system-test/pipeline.ts` verifying that pipelines constructed with
references from uninitialized clients compile, execute, and successfully
retrieve documents from the live backend.
danieljbruce added a commit that referenced this pull request Sep 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[9.2.0](firestore-v9.1.0...firestore-v9.2.0)
(2026-09-16)


### Features

* PNPM workspace
([#8973](#8973))
([1ea27c9](1ea27c9))


### Bug Fixes

* **firestore:** Allow uninitialized client references in pipeline
sources
([#9318](#9318))
([435bcae](435bcae))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Daniel Bruce <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: firestore Issues related to the Firestore API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing DocumentReference to Firestore.pipeline().documents() throws "Error: INTERNAL ERROR: Client is not yet ready to issue requests."

2 participants