-
Notifications
You must be signed in to change notification settings - Fork 119
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
fix(datastore): Observe Query should not return deleted items, fixes - #2069 #2522
Conversation
…te case. Move onObservationStarted and itemChange Subscription within queryLocalData invocation
…ase. Move onObservationStarted and itemChange Subscription within queryLocalData invocation
….com/aws-amplify/amplify-android into ankpshah/observe-query-deleted-items
…into ankpshah/observe-query-deleted-items Syncing ankpshah/observe-query-deleted-items branch with main
…into ankpshah/observe-query-deleted-items Sync up with main branch
* @throws DataStoreException DataStoreException | ||
*/ | ||
@Test(expected = AssertionError.class) | ||
public void observeQueryShouldFailIfReturnsDeletedRecord() throws InterruptedException, DataStoreException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this test? Why would observe query return a deleted record with the fix in place? If were forcing the wrong behavior in a test, this isn't a valid test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed this test as it was redundant and testing the same behavior.
}, | ||
onObservationComplete::call | ||
); | ||
onObservationStarted.accept(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Is it strictly necessary for the onObservationStarted
to be so late?
There is a slight behaviour change here in that if the initial query fails the caller will never see the onStarted callback, only onError (prior behaviour was to see onStarted and then onError). I'm not sure that is a problem, in fact it may be more correct than the prior implementation.
I was also looking at whether it would be possible for onItemChange
to get invoked prior on onObservationStarted
, it's a bit ambiguous to me but I don't think so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had requested this change after diving in together because it was easy to replicate incorrect values and counts if mutations were made before the initial query was successful. Once we report onObservationStarted
, my expectation is that no observations would be missed once that value is returned. This was not the case with the immediate callback.
If completeItemMap
is empty (which is the case before its populated with initial values from a successful query, any item changes (such as a delete) will not properly be updated/removed from competeItemMap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks.
*Issue #, if available: #2069
*Description of changes:
Title: Fix for the bug: ObserveQuery returning deleted items
Change Description:
Additional Notes:
a. Missing case for Delete StorageItemType.
b. OnObservationStarted event being emitted before consumer subscribing to subject. This caused first deleted record to appear in offline deletion scenario within observeQuery response in case of multiple deletions due to asynchronous execution.
c. Deletion event being processed before queryLocalData could populate instance variable completeItemList with model records.
*How did you test these changes?
Two Unit test cases added to test the change.
Documentation update required?
General Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.