-
Notifications
You must be signed in to change notification settings - Fork 894
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
Equality check for timestamp fields fails when caching is active in a web worker. #8031
Comments
@sethrevelle, I'm having trouble reproducing the issue. I cannot run the code exactly as your provided, but I wrote the following code and ran it in a web worker. The code consistently
Can you do some testing on your end by directly using |
@MarkDuckworth I ran some testing on my end. Your code indeed seems to work happily. I changed my code to using Timestamp.fromMillis(ms) as suggested, but it still fails to return results. Interestingly (at least w/o being familiar with the internals of things) query below also returned 0 results until at least 1 second of time was added to the < query constraint. // fails until at least 1000 ms of time added to < portion Another possible contributor is that I previously was calling I have attached log file below. |
The issue does not reproduce for me in incognito mode, or in firefox. It does reproduce in chrome if I launch it in debug mode w/ VSCode. I haven't done anything to create indexes on IndexedDb manually, so I would concur that the indexes were auto-created. Looking at the stack trace @ 00:03:42:136 , I am seeing my code reporting an empty array, and then the snapshot metadata at line 1054. The line immediately before this though ( line 1012 at 00:03:42.134 ) is interesting : 00:03:42.134 [2024-02-21T05:03:42.134Z] @firebase/firestore: Firestore (10.7.2): WebChannelConnection RPC 'Listen' stream 0x5068812e sending: {"database":"projects/service-vanguard/databases/(default)","addTarget":{"query":{"structuredQuery":{"from":[{"collectionId":"resourceDayAddressRouting"}],"where":{"fieldFilter":{"field":{"fieldPath":"resourceDay"},"op":"EQUAL","value":{"timestampValue":"2024-02-20T05:00:00.000000000Z"}}},"orderBy":[{"field":{"fieldPath":"name"},"direction":"ASCENDING"}]},"parent":"projects/service-vanguard/databases/(default)/documents/service-providers/aKgDbsxAm0iCTnZR53cp"},"targetId":12376,"resumeToken":"CgkI4L2gntO7hAM=","expectedCount":60}} The "expectedCount" at the end of the line matches the correct count of rows, if the rows were returned. Below is the screenshot of the collectionGroupIndex config: |
Good news, bad news. I'm able to reproduce. We will investigate further and update you here. |
@sethrevelle, We've identified the root cause and we are working on a solution. In the meantime, the workaround for you and other affected customers is the following:
Note: the issue only affects the Web SDK when persistence is enabled, and only for queries filtering on Timestamp values, and only if there is a client side index on that collection+field. |
@MarkDuckworth I am currently transforming equality queries -> timestamp >= x and timestamp < x + 1s , which seems to work as well (at least in my testing). Is there any reason to believe this will not also consistently produce correct matching documents? For various reasons it is more convienient at moment for my use case. |
Operating System
Ubuntu 22.04.4 LTS
Browser Version
Chrome Version 121.0.6167.160 (Official Build) (64-bit)
Firebase SDK Version
10.7.2
Firebase SDK Product:
Auth, Firestore
Describe your project's tooling
Angular 16.2.9. Firestore is running within a web worker.
Describe the problem
When firestore caching is active, equality query's for Time Stamp fields do not return expected results. I have a set of documents sharing a common TimeStamp of exactly 2024-02-20 . When I query with caching disabled, I correctly get back results. When caching is enabled, no results are returned.
Steps and code to reproduce issue
const app = initializeApp(data.config);
db = initializeFirestore(app, { ignoreUndefinedProperties: true, localCache: persistentLocalCache(/settings/{tabManager: persistentSingleTabManager({forceOwnership:true})},), });
Below Fails (returns 0 documents w/ metaData from cache: true, never returns again):
const coll = collection(db, "/service-providers/aKgDbsxAm0iCTnZR53cp/resourceDayAddressRouting");
const que = query(coll,...[where("resourceDay","==",startOfDay(new Date(2024,1,20)))]);
onSnapshot(que, (querySnapshot) => {
const metaData = querySnapshot.metadata;
const docs = [];
querySnapshot.forEach((doc) => {
const docData = doc.data();
docs.push(docData);
});
console.log(docs);
);
But if you change query to look for :
const que = query(coll,...[where("resourceDay",">=",startOfDay(new Date(2024,1,20))),
where("resourceDay","<",addSeconds(startOfDay(new Date(2024,1,20)),1))]);
All 60 rows come back, with the identical timestamp value for resource day specified when querying for equality. (seconds and nanoseconds).
Timestamp(seconds=1708405200, nanoseconds=0)
If you initialize firestore without caching i.e. : db = initializeFirestore(app, { ignoreUndefinedProperties: true });
Then you also get the full 60 rows when checking for exact equality
const que = query(coll,...[where("resourceDay","==",startOfDay(new Date(2024,1,20)))]);
The text was updated successfully, but these errors were encountered: