mentrena / SyncKit

Automatic CloudKit synchronization
https://mentrena.github.io/SyncKit/
MIT License
507 stars 59 forks source link

Rollback on permissionFailure error #158

Closed torfluor closed 3 years ago

torfluor commented 3 years ago

I have noticed that changes to a shared database is sometimes not accepted by the iCould server. I have seen this after a user deleted a record that have been shared with him. The user has read/write permissions, and is able to add and edit records to the shared database, but not delete them. The sync fails with partialFailure, and when I unwrap the error I see that a permissionFailure is the reason for the failure.

The record is now deleted in the local database, but as the sync is not allowed it is not deleted on the server. Is there some way I can roll back the change when an error like this happen and download the record from the server again, so that the local database is in sync with the server?

mentrena commented 3 years ago

We chatted about this, but for anyone else reading the thread: There seems to be a bug on CloudKit where if you try to delete several records that have a parent-child relationship CloudKit will fail the operation. The solution is to delete only the parent record, and let CloudKit cascade delete the children (which will also get deleted locally next time SyncKit syncs). The docs don't mention any such behaviour so the expectation continues to be that one should be able to delete any records, despite them being related. The bug has been reported to Apple.