Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"CoreData could not fulfill a fault" error on deleting core data

This is the line of code I'm using, which is causing the problem:

[self.managedObjectContext deleteObject:object];

And then when it saves the context, it causes the crash:

Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault'

EDIT: Running the code with '-com.apple.CoreData.SQLDebug 1'.

CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: DELETE FROM ZENTRY WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: COMMIT
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCREATIONDATE, t0.ZMESSAGE, t0.ZSECTIONIDENTIFIER, t0.ZVERSION FROM ZENTRY t0 WHERE  t0.Z_PK = ? 
CoreData: annotation: sql connection fetch time: 0.0042s
CoreData: annotation: total fetch execution time: 0.0096s for 0 rows.
    CoreData: annotation: fault fulfilled from database for : 0x209010 <x-coredata://[edited out long code here]/Entry/p34>
 *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault'

Not sure if this is any help in finding where the problem lies?

like image 548
Andrew Avatar asked Dec 27 '22 02:12

Andrew


1 Answers

I think you need to provide a bit more "context" for this question.

However, there are a few places to look for your problem. First, are you using multiple ManagedObject Contexts? If so, make sure self.managedObjectContext is the same as object.managedObjectContext.

Are you using multiple threads? If so, then you must be using multiple MOCs. Make sure you are only using a MOC on "its" thread.

If you are using the containment policy, that means using the MOC on the thread you created it. If one of the other two, then you should be executing MOC code within performBlock or performBlockAndWait.

Grab the object id of the object being saved, and see if it is in the SQL file.

You can turn on the core data sql debugging flag (add "-com.apple.CoreData.SQLDebug 1" to arguments passed on launch in the scheme) and watch the SQL statements log to console as your app runs. It can help you track down what's really happening.

I think that's enough for now...

EDIT

Some other debugging stuff...

With the context, dump all it's idea of state. inserted/deleted/registered/updated objects, propogatesDeletesAtaaendOfEvent, retainsRegisteredObjects, etc...

Basically, these types of problems are very difficult to track down without lots of information, especially if you are only using one thread and one MOC... because most issues result from using multiple MOCs and/or threads.

like image 181
Jody Hagins Avatar answered Apr 20 '23 00:04

Jody Hagins