Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData: "Dangling reference to an invalid object." error

I'm working on a Cocoa-Touch app, it uses CoreData and has some NSPersistentObject subclasses generated by the XCode model editor.

I've noticed that recently, when saving the context I get an error which has as user info the following part:

(gdb) po ui {     "Dangling reference to an invalid object." = <null>;     NSAffectedObjectsErrorKey = <dump #1 of someObject>;     NSLocalizedDescription = "Operation could not be completed. (Cocoa error 1550.)";     NSValidationErrorKey = <someKey pointing to someObject #1>;     NSValidationErrorObject = <dump #2 of someOtherObject which points to the dump #1 object>;     NSValidationErrorValue = { <list of someMoreObjects> }; } 

There are on other keys in the user info dictionary.

All the dumps I get are valid objects, I've verified them all.

NSValidationErrorObject is an object which has an NSSet which contains objects of types dumped in NSAffectedObjectsErrorKey and NSValidationErrorValue. But all these objects are valid.

Furthermore, this happens randomly, sometimes it happens, sometimes not, and sometimes the list dumped in NSValidationErrorValue is longer, sometimes shorter.

I have no clue why this is happening, or what exactly the error is. Does anyone know what's going on? Any ideas what might cause this bizarre error?

like image 261
Prody Avatar asked Jan 05 '10 01:01

Prody


1 Answers

This error usually arises because a relationship is set improperly often when an object is left without a necessary reciprocal relationship. The object is "dangling" because the object graph says it should be in a relationship but it is just hanging off in space unconnected to any other object. The object is still valid in the sense that it is internal consistent but it's not in a valid place in the graph.

like image 70
TechZen Avatar answered Sep 23 '22 06:09

TechZen