-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Cloud Firestore .where() in operator doesn't work for numbers #3004
Comments
Interesting - the javascript seems to be just feeding the modifiers to native So - android or ios? I'm better at Java, so I see it flowing down to here:
I'm guessing something coming out there is unexpected, and some judicious use of "System.out.println()" inside node_modules in there might turn up the problem |
@mikehardy I have done some more research on this bug and here's what I have found:
Is it necessary to use the type map when passing the query parameter from JS to native? |
The problem with doing
This is for performance, the data being sent over the bridge is pretty massive so the conversion slims it down. |
@Ehesp I see, that make sense. So to fix this the code should distinguish between int and double on the JS side and then add another type on both sides? |
Yeah, grab as a double, check if it is actually a double - if not, typecast as int maybe? Need to have a play. |
Hello 👋, to help manage issues we automatically close stale issues.
|
Just pushed up a fix - will get a release out soon. |
@Ehesp Hi, I have just updated the library and its working on Android now, thanks! Any idea when will this be fixed on the iOS side as well? Thanks! |
@Ehesp I'm also facing with the same problem. It is working fine on Android, but on iOS the
|
Currently, I have the same problem when using a clause similar to
it is maintained without returning results, even if there are any. |
cc @Ehesp looks like this is also not working on iOS |
Initial PR added at #3895 |
Additional tests added that confirm the issue has been resolved. Please feel free to reopen if the issue can be replicated |
still not working on iOS, any workarounds? |
HI @nitnk9. Can you provide an example and perhaps some input which shows this is incorrect. This may be an edge case we have not considered yet? |
It was probably a firebase backend error. The problem was with where in query for array of integers, I changed my code base to work with strings, but now it seems to work with integers too. |
Very strange. Okay, if we can get a reproduction case (a simple App.js or something) that reproduces it in the future we can always reopen - glad you're moving forward! |
This issue is still occurring:
Above query properly works on Android but on iOS always return empty collection. When changing data model to array with strings then works perfectly fine. |
My previous comment is still valid - but even more importantly it sounds like you have a repro case - if you reach right into node_modules the objective-c isn't that hard to work with, you can log what exactly is being sent as a query and it might be a trivial fix? |
I just got bitten by the change in commit 13a6560. I don't believe this can be the correct fix. As it is now, Android and iOS send different objects for the same RN code -- which I'm sure should never happen. The result in my case was that a Cloud Function I wrote to read new documents worked on one platform but not the other. Even though the documents appear the same in the Firestore console, they're not identical: in Android-created documents, the value appears in the (For now, I will stringify numbers before sending them, but this is obviously not a reasonable long term solution.) |
@adapptorsimon what you describe should not happen, no - if you have a patch for Obj-C that would harmonize the two that would be helpful 🙏 |
Hello - I noticed this is marked as 'Resolution: Fixed' so I just wanted to share that it definitely is not resolved. On iOS it is entirely impossible to call a with() Now we are evaluating having to change the format of our datastore to use strings in stead of numbers in order to correct a bug within this library which, frankly, is unfortunate. Our datastore is already populated with production data. |
@Davidson-Mike my previous previous comment is still valid ☝️ |
Hi Mike - I understand your desire for an easily executable snippit to debug this issue. Unfortunately the issue with creating an easily reproducible example is that the issue itself can not be easily reproduced through something like a test. This is because if you create the document using this library, on iOS, then it will succeed in querying the result. The issue is present if the document was created through another source. Obviously I don't believe it is intended for this library to only be fully compatible with records it makes itself for iOS, on iOS. In order to consistently reproduce this issue you must create the document through something like the Firebase Console or another Firebase API. Personally - I have re-created the issue consistently by creating the document via the official Attempting this query would then return an empty array on iOS while working fine on Android; I hope this provides enough information for you to more easily debug this issue, and hope you understand that I would happily provide you a simple example if I could but at the very least it would have to be two separate and different examples run in sequence on different platforms. I suppose I can do that if this still wasn't enough - let me know. |
You indicate that if you create it on android it will then fail on ios, in a react-native context that means that in one sample app.js you could have a create doc / fetch doc for platform android, and on ios you could have a fetch and it would reproduce I think? That would allow for a manual look at it - I imagine the thing is going to be trivially small as a repro, but exchanging executable code vs prose is always more efficient if at all possible Not sure how to exercise this in the e2e harness except via a cloud function that generated the data we expect to work, followed by android + ios fetching it (with android expected working ios expected failing, on the problematic input) |
@mikehardy yes, that is correct. I created the example per your request, tested, and have confirmed that it recreates the issue every time. I also confirmed that after changing the type manually in firebase to a String (and updating the array in code) the issue is resolved. I then changed it back to a 'Number' and it went back to returning no results. Obviously you will need a react-native project bootstrapped, as well as Firebase/Firestore configured. I created a collection called 'exampleCollection' and nothing more. First run the example on Android, it will print a success message. Then run it on ios where it will print a result size. App.js;
|
validate that types go into and come out of firestore consistently using different SDKs This probes the problem from #3004
* feat(firestore): fix iOS Long/Double conversion #3004 * Add special -0 handling * Add tests Co-Authored-By: Mike Hardy <github@mikehardy.net> BREAKING CHANGE: Previous versions of firestore here incorrectly saved integers as doubles on iOS, so they did not show up in `where`/`in` queries. You had to save numbers as strings if you wanted `where`/`in` queries to work cross-platform. Number types will now be handled correctly. However, If you have integers saved (incorrectly!) as double (from previous versions) and you use where / in style queries on numbers, then the same document will no longer be found via .where. Mitigation could be to go through your whole DB and load and re-save the integers correctly, or alter queries. Please test your where / in queries that use number types if this affects you.
i got a problem, i will like to check if a userId or a UserIDD === to the persons user.uid in firestore then document should display the or is not working I used this for or || code below .where( is it possible to do this .. if not how else can I go about it |
@sheggietyn not sure why it isn't working for you but I do that all the time. This is the line from my production app,
|
Issue
When using
where()
andin
for queries, numbers does't work.In order to find out if this is
react-native-firebase
's bug or Firestore simply does not supportin
numbers, I have used the JS SDK for web to perform the same query and it worked. So I came to the conclusion that this is a bug inreact-native-firebase
.Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:iOS
Click To Expand
ios/Podfile
:AppDelegate.m
:Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:android/app/build.gradle
:android/settings.gradle
:MainApplication.java
:AndroidManifest.xml
:Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:6.2.0
Firebase
module(s) you're using that has the issue:Firestore
TypeScript
?N
Think
react-native-firebase
is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: