NSPersistentDocument sometimes shows incorrect file save warning

Originator:hal
Number:rdar://7932809 Date Originated:02-May-2010 05:26 PM
Status:Open Resolved:
Product:Mac OS X Product Version:10.6
Classification:Serious Bug Reproducible:Always
 
02-May-2010 05:26 PM Hal Mueller:
NSPersistentDocument sometimes shows incorrect file save warning

Summary: When using an NSPersistentDocument, sending save: to any NSManagedObjectContext connected to the NSPersistentDocument's Persistent Store Coordinator causes the eventual appearance of this warning when a File->Save is attempted:

"This document's file has been changed by another application since you opened or saved it. The changes made by the other application will be lost if you save. Save anyway?"

This effectively makes NSPersistentDocument a single-MOC class, since a MOC is useless without a working -save: operation.

Steps to Reproduce:
Open, build, and run the attached Xcode project. Save the document (command-S). 

Click the "Main thread import (default MOC, no saves)" to simulate an import of records (programmatic insertion) into the NSPD's default MOC, without any intermediate saves. Program behaves correctly.

The other four import buttons all cause failures. These cases are:
Main thread import using the default MOC, with periodic -save: messages and one after all imports.
Main thread import using a separately created MOC, with periodic and end-of-import -save: messages.
Import on a separate thread using a separately created MOC, with periodic and end-of-import -save: messages.


Expected Results:
File can be saved normally under all 5 scenarios.

Actual Results:
Any use of -save: causes a dialog that is confusing and frightening to application customers.

Regression:
I believe, but am not certain, that this dialog did not appear in CD applications under 10.4; I'm not sure about 10.5;

Notes:
This behavior is peculiar to NSPersistentDocument. A similar example (which was the original basis of the attached project) uses Core Data and multithreaded import, but not NSPersistentDocument, and it works correctly.
http://www.duckrowing.com/2010/03/11/using-core-data-on-multiple-threads/

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!