SyncKit
SyncKit copied to clipboard
Limit exceeded for number of owning references to single record
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?
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;
If I set the action as .none, then the problem is not happening, but then we will lose cascade delete.
This is because CKReference has a limit of 750! Don't use it :) See my https://github.com/lake-of-fire/BigSyncKit fork