-
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
🔥 [🐛] Firestore integer and floating point types all mapped to floating point #4766
Comments
Indeed. This sounds like something in the serializer related to all numbers in javascript being floating point. Our test rules are here: https://github.com/invertase/react-native-firebase/blob/master/.github/workflows/scripts/firestore.rules We collect issue-specific tests here: https://github.com/invertase/react-native-firebase/blob/master/packages/firestore/e2e/issues.e2e.js I bet with a combination of a new rule and a test that exercised it we could pinpoint the failure (and have a test harness for future that makes sure it's fixed forever) Judging by the code content of the firestore seralizer it only pays attention to "number" (which does conform to javascript the language, though perhaps not firebase-js-sdk)
This has a corresponding entry in the iOS code react-native-firebase/packages/firestore/ios/RNFBFirestore/RNFBFirestoreSerialize.m Line 47 in b4fb976
And we do chuck a floating point (well, double) value in for them: react-native-firebase/packages/firestore/ios/RNFBFirestore/RNFBFirestoreSerialize.m Line 381 in b4fb976
(same on Android though you only mention checking iOS at the moment Line 287 in b4fb976
Searching for 'integerValue' in here https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/model/values.ts shows how work needs to be done to correctly separate the idea of integers from doubles for comparison etc on read This is how it is handled when checking whether it is int or float: A quick way to try it might be to have (for android anyway) something like the solutions here https://stackoverflow.com/questions/5502548/checking-if-a-number-is-an-integer-in-java and if it's reasonable to assume the number that came through the react-native bridge to native code is a whole number, pushInteger instead of pushDouble here Line 287 in b4fb976
You can try those native edits directly by reaching right in to node_modules. In general if firestore backend is supporting integers and doubles as separate data types and we are conflating them here as all IEEE floating point numbers, a more complete solution will require more thought |
indeed firestore considers them separate first-class types. 🤔 https://firebase.google.com/docs/firestore/manage-data/data-types |
Thanks for getting on this so quickly @mikehardy. Yep, Firestore's The problem then becomes the inverse, as floats without decimals (e.g. |
Well, react-native-firebase has the stated goal of emulating the firebase-js-sdk. It may be acceptable to follow the exact same duck-typing style firebase-js-sdk does, perhaps with a backwards-compatibility toggle of "all double all the time like before" |
It struck me that modulo provides an excellent workaround to this problem. Should anyone else have this issue, an interim solution would be to change your Firestore rule from:
to the functionally identical but less type specific:
|
Since that is effectively what the javascript is doing in it's duck typing, that may in fact be the "most correct" solution, certainly the "smallest change" one! I think that's clever |
Much obliged. Shall we continue to leave this open for the JS SDK parity goal? |
We discussed this internally and I'm not sure what we can do but it was eye-opening. I do want to leave it open as at minimum we should document the difference, the implications and the way to still get a useful result e.g. in your firestore rules modulus trick |
Hello 👋, to help manage issues we automatically close stale issues.
|
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information. |
This should not have closed, its still an issue - e.g. #5804 |
There still be some type inconsistencies but the most glaring one - that react-native-firebase cannot query docs via numbers using This is the patch that we think fixes it but we are not 100% sure how forwards-/backwards-compatible it is. I have integrated it successfully in a project, and I've successfully made an e2e test here which probes the failure and demonstrates the patch fixes it, so I'm pretty confident it works, but it's a very subtle bug so I would love feedback |
#5840 has been released and should fix this conclusively for iOS in v14+ here |
I seem to be encountering this issue as of v12.9.3. I'm getting the error exactly as stated above:
Which is only resolved when changing my security rules from cc: @mikehardy |
It is not reasonable to expect a version that old to even compile anymore. I can't think of any justification for still using it and I'd be scared to in my work phone projects, personally If this still reproduces on current release it's an issue otherwise upgrade is best recommendation |
Thanks for the reply. You’re right I should update to the latest version. Sorry I didn’t realize I was on such an old version. |
Issue
Any document field rules that assert
is int
contained withinfirestore.rules
cause the following error when a write is attempted using JavaScript integer values for those fields (see example.ts below):This error is resolved if
is int
is changed tois number
. I assume this is due to numeric values of any kind serialising and being sent as float values. However, allowing floats for certain use cases (document order fields, for example) poses a security risk.This does not happen when the web SDK is used.
Project Files
package.json
:firestore.rules
:example.ts
:Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:"@react-native-firebase/app": "^10.4.0"
Firebase
module(s) you're using that has the issue:"@react-native-firebase/firestore": "^10.4.1"
TypeScript
?Y
&^4.1.3
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: