WorryFree Computers   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error in snapshot listener: {"code":"failed-precondition","name":"FirebaseError"} #6613

Closed
MubashirWaheed opened this issue Sep 18, 2022 · 17 comments · Fixed by #6712
Assignees

Comments

@MubashirWaheed
Copy link

[REQUIRED] Describe your environment

  • Operating System version: Ubuntu 20.04.4 LTS
  • Browser version: 104.0 (64-bit) Mozilla Firefox for Ubuntu canonical - 1.0
  • Firebase SDK version: firebase: 9.9.4
  • Firebase Product: firestore

[REQUIRED] Describe the problem

Steps to reproduce:

I am not getting the link to add an index for the compound queries in my console. and instead, I am getting this error in the console
[2022-09-18T05:53:50.590Z] @firebase/firestore: Firestore (9.9.4): Uncaught Error in snapshot listener: {"code":"failed-precondition","name":"FirebaseError"}
After going through stackoverfollow I manually created the composite indexes in the firebase console under the firestore> indexes.

  1. index Descending, createdBy Descending
  2. index Descending, createdBy Arrays

for both indexes

  • collection ID is posts
  • Query scope collection
  • status enabled

When I remove the orderBy there is no error.

Relevant Code:

following is an array with string values and the index field has number as its value
ps: I am using react.

// TODO(you): code here to reproduce the problem
    useEffect(()=>{
        const q = query(
        collection(db, "posts"),
        orderBy("index", "desc"),
        where("createdBy", "in", following)
      );
        const unsubscribe = onSnapshot(q, (querySnapshot) => {
        const data = [];
        querySnapshot.forEach((doc) => {
          data.push(doc.data());
        });
        setPosts(data);
      });
}, [])
@IvoBiaus
Copy link

Im getting the same error after deleting my yarn.lock and running yarn install which in my case, among other things, it updates @firebase/firestore from 3.4.0 to 3.5.0. After doing that, if i try to login in my app and request data from firebase all my rules fail because the request.auth is sending null all of the sudden, and i get the error:
@firebase/firestore: Firestore (9.10.0): Uncaught Error in snapshot listener: {"code":"permission-denied","name":"FirebaseError"}

Screenshot from Firebase Emulator Suit:
image

@MarkDuckworth MarkDuckworth self-assigned this Sep 19, 2022
@MarkDuckworth
Copy link
Contributor

@IvoBiaus, can you update your emulator and let me know if that helps you? A security update was released in 3.5.0 which changed how the SDK authenticates to the back end. This is likely the source of your issue.

@MubashirWaheed, your issue looks different, but it would be worth updating the emulator if you are seeing this issue when using the emulator and also on Firestore 3.5.0 / Firebase 9.10.0. Just a thought, do you get any additional error info in the network trace of the browser console?

@MubashirWaheed
Copy link
Author

@MarkDuckworth I updated the firebase in my react project to 9.10.0 but I am still get the same error and no I am not getting any other error in network tab.
Also a point to note is I am using firebase console instead of emulator

@MarkDuckworth
Copy link
Contributor

@MubashirWaheed, thanks for checking on that. I was getting the same error and then I configured this index

  • Collection ID = products
  • Fields Indexed = createdBy Ascending, index Descending
  • Query scope = Collection

Putting the fields indexed in a different order did not work for me.

@MubashirWaheed
Copy link
Author

@MarkDuckworth so do you think it's a firebase sdk bug?

@MarkDuckworth
Copy link
Contributor

Looks like there is an issue when it is not logging a link to create the index. I will confirm with the team.

Did you get your index to work?

@MubashirWaheed
Copy link
Author

A manually created composite index is also not working for me

@MarkDuckworth
Copy link
Contributor

Execute getDocs(q) instead of onSnapshot(q, ...). That will give you the link you need to create the correct index.

@chocobuckle
Copy link

On 9.9.4 and 9.10 I'm not getting the link. Had to rollback to 9.8.4 to get it again. Quite a showstopper this.

@chocobuckle
Copy link

Just for the record, I didn't try 9.9.0 - 9.9.3, so can't confirm if they give the link or not.

@MarkDuckworth
Copy link
Contributor

Thanks for the continued updates. We're looking to get this fixed.

In the meantime if this is affecting you pass your query to getDocs() instead of onSnapshot() one time to get the link to generate the index.

@MubashirWaheed
Copy link
Author

Sorry for the delayed response but I have the indexes working. As you suggested I used getDocs() to get the link to create the correct index

@ahmadaIanazi
Copy link

I'm having exactly the same issue. on React-Native Expo.

I think it has nothing to do with Expo or react. Its mostly based on Firestore indexing !

When I removed the orderBy it started working. If I remove the where() it also works. But together ! They dont work !.

export const commentListener = (postId, setCommentList) => { const collectionRef = collection(db, 'comments'); const postID = postId console.log(postID) const q = query( collectionRef, where('postId', '==', postId), orderBy('creation', 'desc') ); onSnapshot(q, ((snapshot)=> { let comments = snapshot.docs.map((doc) => { const id = doc.id; const data=doc.data(); return { id, ...data} }) setCommentList(comments) })) };

This shows an Error {"code":"failed-precondition","name":"FirebaseError"}

But remove either the 'where( ... )' or the 'orderBy(...)' then there is no error. ! I hope someone solve this, I need to move on with my code and live without indexing by date ..untill I figure it out tomorrow.

@DevYuns
Copy link
DevYuns commented Oct 21, 2022

Execute getDocs(q) instead of onSnapshot(q, ...). That will give you the link you need to create the correct index.

getDocs(q) makes index link properly. Thank you!

@milaGGL
Copy link
Contributor
milaGGL commented Oct 24, 2022

Hi @MubashirWaheed. An error handler should be able to help with this problem: https://firebase.google.com/docs/firestore/query-data/listen#handle_listen_errors

Could you please try this code and see if we can get the expected error message with a link to generate the index. Once the composite index is generated, the error should go away.

// TODO(you): code here to reproduce the problem
  useEffect(() => {
    const q = query(
      collection(db, 'posts'),
      orderBy('index', 'desc'),
      where('createdBy', 'in', following)
    );
    const unsubscribe = onSnapshot(
      q, 
      querySnapshot => {
        const data = [];
        querySnapshot.forEach(doc => {
          data.push(doc.data());
        });
        setPosts(data);
      }),
      error => {
        // if index is missing, error message should provide a link to generate required index.
        console.log(error);
      };
  }, []);

Meanwhile, we will be keep looking into default error handling to improve customer experience.

@milaGGL
Copy link
Contributor
milaGGL commented Oct 28, 2022

FIY, the bug fix has been merged, and will be included in the next release.

@dconeybe
Copy link
Contributor

The bug fix was released in 9.14.0 released November 10, 2022: https://firebase.google.com/support/release-notes/js#version_9140_-_november_10_2022

@firebase firebase locked and limited conversation to collaborators Nov 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants