Repository navigation
fix(firestore): allow uninitialized client references in pipeline sources - #9318
Conversation
There was a problem hiding this comment.
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.
| if (reference.firestore === this.db) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
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.
| if (reference.firestore === this.db) { | |
| return true; | |
| } | |
| if (reference.firestore === this.db) { | |
| return; | |
| } |
7fde20a to
3bfbbfd
Compare
…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.
🤖 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]>
Fixes #9186
Problem
When
DocumentReferenceorCollectionReferenceinstances are passed tofirestore.pipeline().documents(...)orfirestore.pipeline().collection(...),PipelineSource._validateReference()accessedthis.db.formattedNameandreference.firestore.formattedName.formattedNamesynchronously evaluatesthis.projectId, which throws: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
PipelineSource._validateReference():reference.firestore === this.db, returntrueimmediately without inspectingformattedName. References created from the same client instance always belong to the same database._projectIdanddatabaseIdwithout triggering premature synchronous initialization.dev/test/pipelines/pipeline.tsverifying 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.dev/system-test/pipeline.tsverifying that pipelines constructed with references from uninitialized clients compile, execute, and successfully retrieve documents from the live backend.