firebase / firebase/firebase-js-sdk

Documents deleted with a function don't update the local cache if persistence is enabled

Open
#3,838 11 comments 5 reactions 1 assignee Assigned to @yuchenshi View on GitHub
api: firestore bug internal-bug-filed
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### [REQUIRED] Describe your environment

* Operating System version: macOS Catalina 10.15.6
* Browser version: Chrome 85.0.4183.102
* Firebase SDK version: 7.20.0
* Firebase Product: Firestore

### [REQUIRED] Describe the problem

Documents deleted with a function don't update the local cache if persistence is enabled.

I am running the firebase emulator. I call a firebase function that deletes an entire collection of documents. The collection disappears from the emulator and when persistence is not enabled, the documents are now gone from query results.

However, when persistence is enabled, Firestore returns those documents when queried, regardless of the specified source. For example, if I specify `server` as the `source`, the resulting list of documents still contains those deleted documents. The query metadata indicates that the query results are from the server, but that is not the case. Here is the metadata when source is set to server: `{ fromCache: false, hasPendingWrites: false }`. This is correct, but the collection of returned docs is not.

If I disable persistence, the problem goes away and I am returned the fresh collection - empty as expected.

This is a pretty serious bug that prevents anyone from using Firestore persistence in conjunction with firebase functions that manipulate document collections.

#### Steps to reproduce:

1. Create a firebase function that deletes a collection of documents.
1. Enable persistence on the client.
1. Fetch collection of documents.
1. Call function that deletes the same collection of documents.
1. Fetch collection of documents on client with `source` set to `server`.
1. Notice that the query metadata indicates that query results are from the server `{ fromCache: false, hasPendingWrites: false }` but the collection of documents includes all of the documents deleted by the function.

I can't seem to get the latest results from that collection (I expect to receive an empty result) unless I disable persistence, at which point the query result returns an empty list, as expected.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.