NSFetchedResultsController section key paths in nested Managed Object Contexts
| Originator: | evan | ||
| Number: | rdar://15612154 | Date Originated: | 07-Dec-2013 09:35 PM |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 7.0.4 |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: When using a FRC with a section key path, the results when fetching against a child context are sometimes surprising Steps to Reproduce: App Delegate's child managed object context save operation causes managed objects to be saved into it's parent managed object context (colloquially referred to as "pushing saves up one level"). However, if the parent managed object context does not persist these objects to disk (meaning: parentContext.hasChanges == YES), thereby obtaining permanent object IDs, then the fetched results controller does not create sections based on the keypath passed at initialization. I believe this has *something* to do with Key-Value Coding. Overriding -[NSManagedObject valueForKeyPath:] yields the following interesting backtrace when the fetched results controller fetches on a dirty managed object context that is directly connected to a persistent store coordinator: frame #0: FetchedResultsController`-[FHKEvent valueForKeyPath:](self=0x08c7dd90, _cmd=0x012a5b93, keyPath=0x00005888) + 57 at FHKEvent.m:15 frame #1: CoreData`-[NSFetchedResultsController(PrivateMethods) _sectionNameForObject:] + 50 frame #2: CoreData`-[NSFetchedResultsController(PrivateMethods) _computeSectionInfo:error:] + 1151 frame #3: CoreData`-[NSFetchedResultsController performFetch:] + 1021 frame #4: FetchedResultsController`-[FHKViewController fetchedResultsController](self=0x08a9ef70, _cmd=0x000043e8) + 700 at FHKViewController.m:39 frame #5: FetchedResultsController`-[FHKViewController numberOfSectionsInTableView:](self=0x08a9ef70, _cmd=0x00998b00, tableView=0x09295000) + 78 at FHKViewController.m:78 frame #6: UIKit`-[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 102 frame #7: UIKit`-[UITableViewRowData invalidateAllSections] + 69 frame #8: UIKit`-[UITableView _updateRowData] + 194 frame #9: UIKit`-[UITableView _ensureRowDataIsLoaded] + 45 frame #10: UIKit`-[UITableView numberOfSections] + 35 frame #11: UIKit`-[UITableViewController viewWillAppear:] + 103 --snip-- However, when the fetched results controller fetches on a "clean" child (hasChanges == NO) of a dirty parent context (that parent context dirtied by a save pushing changes up), -[NSManagedObject valueForKeyPath:] isn't called after -[NSFetchedResultsController _computeSectionInfo:error:]. -[NSFetchedResultsController _sectionNameForObject:] isn't called at all in this situation. Project: https://github.com/evandelaney/AppleBug-15612154
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!