question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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.

image

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:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
yuchenshicommented, May 16, 2020

Fix coming in the next release.

2reactions
zanonacommented, Dec 11, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found