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

when fromFirestore returns undefined it leads to: FIRESTORE (10.5.0) INTERNAL ASSERTION FAILED: Unexpected state #7719

Closed
vdanchenkov opened this issue Oct 24, 2023 · 3 comments

Comments

@vdanchenkov
Copy link

Operating System

MacOS

Browser Version

Chrome 117.0.5938.149

Firebase SDK Version

10.5.0

Firebase SDK Product:

Firestore

Describe your project's tooling

Next.js app

Describe the problem

In our project we actively use withConverter. Some of converters sometimes returns undefined when they see logically null value. It worked fine in version 8.10.1

After update to the 10.5.0 version with compat enabled we are getting exceptions on reading data() from the elements of the collection.

It does not happen when document is accessed directly by it's path.

Error comes from this code:
https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore-compat/src/api/database.ts#L975

Steps and code to reproduce issue

let converter = {
  toFirestore: (x) => x,
  fromFirestore: (snapshot, options) => {
     const data = snapshot.data(options);
     // if data is empty return undefined
     return undefined;
  }
}

let collection = firestore.collection("someExistingCollection").withConverter(converter)

collection.get().then(x => x.docs.forEach(xx => console.log(xx.data())))
@vdanchenkov vdanchenkov added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Oct 24, 2023
@dconeybe
Copy link
Contributor

Drive-by comment: This looks like a legitimate bug to me. It appears that the code that the customer linked to fails to take into account that the undefined result may be coming from a converter, in which case undefined is a completely valid return value. A valid fix may be to simply change the assertion from data !== undefined to data !== undefined || this._delegate.converter (note: untested code -- may not compile)

@jbalidiong jbalidiong added needs-attention and removed new A new issue that hasn't be categoirzed as question, bug or feature request labels Oct 25, 2023
@vdanchenkov
Copy link
Author

I can confirm that the issue does not happen when using modular API.

@tom-andersen
Copy link
Contributor

tom-andersen commented Oct 30, 2023

Issue has been fixed in PR #7738

@firebase firebase locked and limited conversation to collaborators Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.