SyncKit icon indicating copy to clipboard operation
SyncKit copied to clipboard

Limit exceeded for number of owning references to single record

Open sskjames opened this issue 1 year ago • 3 comments

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 avatar Aug 29 '24 09:08 sskjames

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 avatar Aug 29 '24 10:08 sskjames

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

sskjames avatar Aug 29 '24 10:08 sskjames

This is because CKReference has a limit of 750! Don't use it :) See my https://github.com/lake-of-fire/BigSyncKit fork

aehlke avatar Feb 08 '25 08:02 aehlke