Skip to content

Fixing firestore deploy on fresh projects - #9220

Merged
joehan merged 2 commits into
masterfrom
jh-fix-firestore-deploy
Oct 1, 2025
Merged

joehan merged 2 commits into
masterfrom
jh-fix-firestore-deploy

Conversation

@joehan

@joehan joehan commented Sep 30, 2025

Copy link
Copy Markdown
Member

Description

deploy --only firestore was breaking on fresh projects for 2 reasons:

  • First, it tried to call the :test endpoint to compile rules before any database was created. This would fail with 403 errors (presumably it needs p4sa provisioning to be performed?)
  • Secondly, we weren't actually polling on the operation returned by create database, so it would sometimes try to deploy rules before the operation completed.

This PR fixes both.

Scenarios tested

Before, broken:
Screenshot 2025-09-30 at 2 58 50 PM
After, working on a fresh project:
Screenshot 2025-09-30 at 3 19 43 PM

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @joehan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves critical issues preventing firebase deploy --only firestore from functioning correctly on projects without an existing Firestore database. It refactors the database creation process to occur earlier in the deployment lifecycle and introduces robust polling to ensure the database is fully provisioned before proceeding with security rules and index deployments, thereby eliminating 403 errors and race conditions.

Highlights

  • Database Creation Relocation: The logic for creating a Firestore database on fresh projects has been moved from the deploy phase to the prepare phase. This ensures the database exists before any rules or indexes are processed.
  • Pre-deployment Database Provisioning: The createDatabase function is now explicitly called during the prepare step, preventing 403 errors that occurred when attempting to compile rules against a non-existent database.
  • Asynchronous Operation Polling: The database creation API call now includes polling to wait for the operation to complete, resolving race conditions where rules might be deployed before the database is fully provisioned.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@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 correctly identifies and addresses two key issues that caused deploy --only firestore to fail on new projects. The approach of moving database creation to the prepare step and adding polling for the creation operation is sound. However, I've identified a critical bug in the polling implementation where the result is ignored, along with a couple of minor issues like a duplicated API call and a typo. Addressing these points will ensure the fix is robust and works as intended.

Comment thread src/firestore/api.ts
Comment on lines +787 to 793
await pollOperation({
apiOrigin: firestoreOrigin(),
apiVersion: "v1",
operationResourceName: res.body.name,
masterTimeout: 600000,
});
const database = res.body.response;

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.

critical

There's a critical issue here. The pollOperation is awaited, but its return value (the completed operation details) is discarded. The code then tries to access res.body.response, which comes from the initial POST request that started the long-running operation. For long-running operations, this response field is typically not populated in the initial response.

You need to capture and use the result from pollOperation to get the actual database object after creation.

Suggested change
await pollOperation({
apiOrigin: firestoreOrigin(),
apiVersion: "v1",
operationResourceName: res.body.name,
masterTimeout: 600000,
});
const database = res.body.response;
const database = await pollOperation<types.DatabaseResp>({
apiOrigin: firestoreOrigin(),
apiVersion: "v1",
operationResourceName: res.body.name,
masterTimeout: 600000,
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not relevant in this case - Firestore returns the resource in the initial response.

Comment thread src/deploy/firestore/prepare.ts Resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@joehan
joehan enabled auto-merge (squash) September 30, 2025 22:53
@joehan
joehan disabled auto-merge October 1, 2025 02:27
@joehan
joehan merged commit 6e000fb into master Oct 1, 2025
@joehan
joehan deleted the jh-fix-firestore-deploy branch October 1, 2025 02:27
@github-project-automation github-project-automation Bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions Oct 1, 2025
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.

2 participants