NSBatchDeleteRequest does not delete external files
Originator: | RyanIPete | ||
Number: | rdar://34794842 | Date Originated: | 10/3/17 |
Status: | Open | Resolved: | |
Product: | iOS SDK | Product Version: | 11.0.1 (15A402) |
Classification: | Bug | Reproducible: | 100% |
(See https://stackoverflow.com/q/46225247/176304 for a formatted version w/ images) Summary: When using batch delete to delete a core data object, the object's external binary data is not deleted. Steps to Reproduce: I've set up a simple Core Data project. The data model defines an ImageProperty entity with a binary data attribute that "Allows External Storage". I don't make any changes to the implementation of the persistentContainer that is provided out-of-the-box: ```swift lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "ExternalStorage") container.loadPersistentStores(completionHandler: { (storeDescription, error) in ... }) return container }() ``` On application launch, I create and save an instance of `ImageProperty` with data large enough to be stored externally. I then immediately delete that property using a batch delete: ```swift let entityName = String(describing: ImageProperty.self) // Create property let entity = NSEntityDescription.entity(forEntityName: entityName, in: persistentContainer.viewContext)! let property = ImageProperty(entity: entity, insertInto: persistentContainer.viewContext) property.data = NSData(contentsOfFile: Bundle.main.path(forResource: "sample-house-a", ofType: "jpg")!) try! persistentContainer.viewContext.save() // Batch-delete property let fetch: NSFetchRequest = NSFetchRequest(entityName: entityName) let request = NSBatchDeleteRequest(fetchRequest: fetch) _ = try! self.persistentContainer.viewContext.execute(request) as! NSBatchDeleteResult try! self.persistentContainer.viewContext.save() ``` Expected Results: The item has been deleted from the database, and the external file has been deleted from the _EXTERNAL_DATA folder. Actual Results: The item has been deleted from the database, but the external file has been deleted from the _EXTERNAL_DATA folder. Version/Build: iOS 11.0.1 (15A402) Configuration: Xcode 9.0 (9A235) Deployment Target: 11.0 Default "Debug" configuration
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Marked as duplicate
Message from Apple on July 5, 2018:
Still open as of Oct 8, 2018.