mentrena / SyncKit

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

Limit exceeded for number of owning references to single record #192

Open sskjames opened 2 months ago

sskjames commented 2 months ago

When a record is referred by more than 750 other records, I get this error:

<CKError 0x15fccbdf0: "Partial Failure" (2/1011); "Failed to modify some records"; .....
partial errors: {
RecordTypeA.A6A0F60C-A460-4ABB-AC73-684F6BF6181B:(QSCloudKitCustomZoneName:__defaultOwner__) = <CKError 0x117adc980: "Limit Exceeded" (27/2023); server message = "Limit exceeded for number of owning references to single record";
....
... 9 "Batch Request Failed" CKErrors omitted ...
}

I could consistently recreate this problem.

Is this because of cascade delete?

There is a hard limit to the number of references with a [CKRecord.ReferenceAction.deleteSelf](https://developer.apple.com/documentation/cloudkit/ckrecord/referenceaction/deleteself) action that any one record can have. 
This limit is 750 references, and any attempt to exceed it results in an error from the server.

Ref: CKReference

Is there a way to resolve this?

sskjames commented 2 months ago

The problem could be here in the recordToUpload method in RealmSwiftAdapter.

 // if we set the parent we must make the action .deleteSelf, otherwise we get errors if we ever try to delete the parent record
                        let action: CKRecord.ReferenceAction = parentKey == property.name ? .deleteSelf : .none
                        let recordReference = CKRecord.Reference(recordID: recordID, action: action)
                        record[property.name] = recordReference;
sskjames commented 2 months ago

If I set the action as .none, then the problem is not happening, but then we will lose cascade delete.