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 QuerySnapshot.documentChanges(includeMetadataChanges: false) always returns DocumentChange with only metadata changes #12728
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
It's difficult for me to determine what is happening in your screenshots because I can't see the full application or document changes. Can you provide a minimal reproducible example? However, I tested the following and did not find any issues.
Creating and sharing a minimal reproducible example can help us more easily diagnose the behavior you are experiencing. |
@MarkDuckworth Thanks for getting back. I've done some more testing and I think this might be related to precision loss for Timestamp/Date field when Firestore compares a local/cache document and a server document. I've tried that when I update the document locally, the snapshot listener always include the metadata change only if the update contains a After some more digging when Here is a basic setup:
|
Firestore has microsecond precision, so it seems expected that the backend truncates the nanosecond-precision value you provided What's not clear to me is how you are setting this nanosecond precision value in the SDK? I'm seeing that the SDK also truncates nano-second precision values to micro-seconds when I attempt to write a date value. |
Got it, thanks for the explanation. Here's how I'm updating the timestamp:
Here's the
|
When I initially tested I was using To get a different behavior from Firestore, it might be worth generating a date or timestamp with microsecond behavior. Also, I would consider using It's unlikely we will modify the current SDK behavior to change the snapshot behavior you are seeing. Such changes could have implications for other current and future users. If you have a path forward, then I will close this issue. |
Thank you for your response. While I understand that changing the current behavior of microsecond precision is challenging (and I'm not proposing to change that), however, I would suggest that the iOS SDK should correctly truncate any passed Date value to microsecond precision. At the very least, we should not expect any timestamp with nanosecond precision from the SDK's own snapshot listener. Using Hope this makes sense! |
Description
In Firestore's
QuerySnapshot#documentChanges
API atfirebase-ios-sdk/Firestore/Source/Public/FirebaseFirestore/FIRQuerySnapshot.h
Line 68 in 03ce722
I've tested the same piece of code in both Android and iOS. In Android, this behaviour works as expected, when I do
querySnapshot.getDocumentChanges(MetadataChanges.EXCLUDE)
, it will return 0 documentChange if there is only metadata changed.Reproducing the issue
For both Android and iOS, I'm using the exact same setup, listening to same collection with the same query, with
includeMetadataChanges
set totrue
.Here's my code in iOS that processes the received
QuerySnapshot
and its log output when I write a new document locally:Here's my code in Android that processes the received
QuerySnapshot
and its log output when I write a new document locally:Firebase SDK Version
10.23.1
Xcode Version
15.2
Installation Method
Swift Package Manager
Firebase Product(s)
Firestore
Targeted Platforms
iOS
Relevant Log Output
No response
If using Swift Package Manager, the project's Package.resolved
Expand
Package.resolved
snippetReplace this line with the contents of your Package.resolved.
If using CocoaPods, the project's Podfile.lock
Expand
Podfile.lock
snippetReplace this line with the contents of your Podfile.lock!
The text was updated successfully, but these errors were encountered: