File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
Tests/SQLiteDataTests/Internal Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -93,16 +93,19 @@ extension SyncEngine {
9393 return ModifyRecordsCallback {
9494 await syncEngine. parentSyncEngine. handleEvent (
9595 . fetchedRecordZoneChanges(
96- modifications: saveResults. values. compactMap {
97- guard let record = try ? $0. get ( ) else { return nil }
98- return record. copy ( ) as? CKRecord
96+ modifications: saveResults. compactMap { recordID, result in
97+ guard case . success = result else { return nil }
98+ // NB: Read the latest version from the database in case the record has been
99+ // modified between the original save and when this callback is invoked.
100+ return try ? syncEngine. database. record ( for: recordID)
99101 } ,
100102 deletions: deleteResults. compactMap { recordID, result in
101- ( recordsToDeleteByID [ recordID] ? . recordType) . flatMap { recordType in
102- ( try ? result. get ( ) ) != nil
103- ? ( recordID, recordType)
104- : nil
105- }
103+ guard case . success = result else { return nil }
104+ // NB: Skip if the record has been re-saved between the original delete and
105+ // when this callback is invoked.
106+ guard ( try ? syncEngine. database. record ( for: recordID) ) == nil else { return nil }
107+ guard let record = recordsToDeleteByID [ recordID] else { return nil }
108+ return ( recordID, record. recordType)
106109 }
107110 ) ,
108111 syncEngine: syncEngine
You can’t perform that action at this time.
0 commit comments