Core Data errors when saving context after syncing from CloudKit

In my new SwiftUI app I am using NSPersistentCloudKitContainer API to persist my data and also share it between multiple different devices.
I am always using viewContext to fetch or save records, also my Stack consists of two custom configurations where CloudKit is enabled. One for entities to be stored in the CK public database and one for records in the private database.

This usually works just fine. I can save or delete records on one device and they appear on the other device. However in some situations, usually after I imported data on device A and use the same device to create a new record I get errors like this when saving context:

Code Block language
Error Domain=NSCocoaErrorDomain Code=133020 "Could not merge changes." UserInfo={conflictList=(
    "NSMergeConflict (0x28126df40) for NSManagedObject (0x28242eda0) with objectID '0xb76a5d0f17dd5aa9 <x-coredata://FA91F3DE-B508-4842-95E0-EF4346521007/Lift/p11>' with oldVersion = 33 and newVersion = 34 and old object snapshot = {\n    id = \"D1E2B253-723C-406C-8566-2307DA2D5C17\";\n    name = bench;\n} and new cached row = {\n    id = \"D1E2B253-723C-406C-8566-2307DA2D5C17\";\n    name = bench;\n}"
), NSExceptionOmitCallstacks=true}


I have no idea why PersistentCloudKitContainer is not able to merge this as the data for both records is practically the same only the version is updated. Also I am assuming that PersistentCloudKitContainer has an automatic merge policy configured by default which is .

I am using Xcode 12 with deployment target also iOS 14

What did I miss here? Any help is appreciated
Did you set a merge policy on your MOC ?
Not explicitly no, am I supposed to? I saw this reply https://developer.apple.com/forums/thread/122745?answerId=382227022#382227022 which mentions that NSPersistentCloudKitContainer does use a custom merge policy (last writer wins) by default which is what I want.
I have exactly the same issue. Anybody has any ideas please? :-)

I can try setting some merge policy but I am not sure if that is the best way as core data and CloudKit are supposed to do the 'last writer wins' by default so I don't understand what is going wrong.
Core Data errors when saving context after syncing from CloudKit
 
 
Q