Deleting document breaks onSnapshot observer in emulator
See original GitHub issue[REQUIRED] Environment info
firebase-tools: 8.2.0
Platform: macOS
[REQUIRED] Test case
When deleting a document that has a query on a user auth property, the following error is throw on the snapshot listener. The goal is to observe all invites that has the users email. It works properly when in production, just not in the emulator.
Using these rules
match /invites/{inviteID} {
function isSignedIn() {
return request.auth != null;
}
function isUserInvite() {
return request.auth.token.email != null &&
request.auth.token.email == resource.data.user_email;
}
allow read: if isSignedIn() && isUserInvite();
allow write: if true;
}
And this basic funciton to observe the collection.
firebase.firestore()
.collection("invites")
.where(`user_email`, '==', myUserEmail) // this would be the users email
.onSnapshot((snapshot) => {
snapshot.forEach( doc => {
console.log(doc.id, doc.data()) // log the invites that belong to the user
})
})
Also have a stack overflow question started: https://stackoverflow.com/questions/61567689/firestore-onsnapshot-rules-throw-error-when-deleting-document
[REQUIRED] Steps to reproduce
// creates a new invite and the snapshot listener informs me
await firebase.firestore()
.collection('invites')
.doc("invite_1")
.set({
user_email: someUserEmail, // use the users email here
date_added: firebase.firestore.FieldValue.serverTimestamp()
})
// deletes the invite, but the snapshot throws an error
await firebase.firestore()
.doc(`invites/invite_1`)
.delete()
[REQUIRED] Expected behavior
The snapshot should always return the query - not throw an error because an item was deleted.
[REQUIRED] Actual behavior
The error FirebaseError: Null value error. for 'get' @ L91
is thrown.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Get realtime updates with Cloud Firestore - Firebase
Get realtime updates with Cloud Firestore · On this page · Events for local changes · Events for metadata changes · Listen to...
Read more >Firestore onSnapshot rules throw error when deleting document
It works for observing new documents, but fails when deleting a document. The following code makes the observer throw an error. // creates...
Read more >https://unpkg.com/firebase%405.8.5/index.d.ts
Database; delete(): Promise<any>; messaging(): firebase.messaging. ... export class Functions { private constructor(); useFunctionsEmulator(url: string): ...
Read more >Building Applications Using Firebase Part 3: Firestore
It is a NoSQL (Not only SQL) document-oriented database. ... The onSnapShot function on our data reference accepts an observer as a callback ......
Read more >Firestore query date range - Chiara Gabbani
onSnapshot (reference, observer) Oct 29, 2021 · If a Collection Group Query ... From the Firebase documentation on query limitations: In a compound...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fix coming in the next release.
I’m afraid this is still an issue when deleting the document from the emulator Firestore dashboard. When the document gets deleted from there
Null value error
is thrown.*Edit: Never mind, it looks like that when read access is given based on
resource
,resource == null
also needs to be allowed.