CoreData: Delete propagation prefetching failed using NSCKImportOperation

I think the reason was a misconfiguration of my background context. It was set to retain all registered objects. As soon as I out commented the respective code, the error was gone:

private (set) lazy var backgroundContext: NSManagedObjectContext! = {
    let context = persistentContainer.newBackgroundContext()
    context.name = "backgroundContext"
    
    // For possible merge policies see <https://developer.apple.com/documentation/coredata/nsmergepolicy/merge_policies>
    context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
    
    /*
    CAUTION: DO NOT ENABLE THE FOLLOWING STATEMENT:
    context.retainsRegisteredObjects = true
    If enabled, the following error is reported indefinitely:
    ShopEasy[20204:2672392] [error] CoreData: Delete propagation prefetching failed with exception: 
    The fetch request's entity 0x600003764630 'NSCKImportOperation' appears to be from a different NSManagedObjectModel than this context's
    */
            
    // Pin the context to the current generation token and set it to keep itself up to date with local changes.
    context.automaticallyMergesChangesFromParent = true
    context.performAndWait {
        do {
            try context.setQueryGenerationFrom(.current)
        } catch {
            fatalError("###\(#function): Failed to pin viewContext to the current generation: \(error)")
        }
    }
    return context
}()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top