You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using FirebaseAuth (6.1.2)
Using FirebaseAuthInterop (1.0.0)
Using FirebaseCore (6.0.3)
Using FirebaseFirestore (1.4.0)
Using FirebaseUI (6.2.1)
I think what I am seeing is the the documented and intended behaviour but it causes a problem in some circumstances.
I would like to be able to create a new document, when both online and offline, and then query for it shortly after. The current behaviour of setData doesn't allow this in Firestore iOS.
When offline the completion callback does not happen, this means I cannot use the callback version of setData to manage program flow in my code. However if I don't wait for the callback while online I sometimes get "Missing or insufficient permissions" errors when querying a document too soon after creating it.
So neither way to call setData is usable both online and offline if you want to query the data soon after creation.
Would it be possible for the completion block to still fire when offline once the document has been written locally and is indexed/queryable? I understand this might be confused as confirmation of a successful write to the db, but this would still be better than no callback. Maybe use an error containing a warning that the write is not confirmed?
Thanks
P
The text was updated successfully, but these errors were encountered:
You're right, the behavior you're seeing is intended.
The good news is that we already guarantee that data you write locally is immediately queryable locally so you don't need to wait for a callback just for local purposes. This means that you can do a getDocument(source: .cache) immediately after writing without waiting for the completion handler to fire. Similarly, snapshot listeners started after the write will show an initial snapshot containing it without any special effort.
Unfortunately, it sounds like you're trying to perform a query whose rules depend on your write succeeding. This is an area that can get complicated because of Firestore's method of applying writes in the background.
I see a few strategies for how to proceed:
Perform the initial permission-granting write in a transaction. This will fail if you're offline but prevent your users from proceeding to the dependent query.
Force queries to run from cache only until you've observed the completion of the write.
This can be tricky to handle across app restarts because we don't yet have an API for resuming writes. If this is the only write you're waiting on for a given document you can estimate whether or not there are still writes pending by listening (with metadata) and wait for hasPendingWrites to become false.
Similar to the above, but ignore the completion handler altogether. Instead just listen to the document that grants the permission (with metadata) and wait for hasPendingWrites to clear before allowing non-local queries.
My best advice is to try to avoid this kind of circumstance altogether, but I realize that's not possible with some data/permission models. Let us know if any of the above strategies works out.
Making this easier is something we're looking to address, but unfortunately extra completion callbacks aren't a way we can do it because our other languages model the result of the setData equivalent with a Promise or a Task which can only fire once.
OSX 10.14.5
Xcode version: 10.2.1
Using FirebaseAuth (6.1.2)
Using FirebaseAuthInterop (1.0.0)
Using FirebaseCore (6.0.3)
Using FirebaseFirestore (1.4.0)
Using FirebaseUI (6.2.1)
I think what I am seeing is the the documented and intended behaviour but it causes a problem in some circumstances.
I would like to be able to create a new document, when both online and offline, and then query for it shortly after. The current behaviour of setData doesn't allow this in Firestore iOS.
When offline the completion callback does not happen, this means I cannot use the callback version of setData to manage program flow in my code. However if I don't wait for the callback while online I sometimes get "Missing or insufficient permissions" errors when querying a document too soon after creating it.
So neither way to call setData is usable both online and offline if you want to query the data soon after creation.
Would it be possible for the completion block to still fire when offline once the document has been written locally and is indexed/queryable? I understand this might be confused as confirmation of a successful write to the db, but this would still be better than no callback. Maybe use an error containing a warning that the write is not confirmed?
Thanks
P
The text was updated successfully, but these errors were encountered: