Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data -existingObjectWithID:error: causes error 133000
    primarykey
    data
    text
    <p>My app uses Core Data (with some help of Magical Record) and is rather heavily multithreaded using <code>NSOperation</code>.</p> <p>Of course I am very careful to only pass around <code>NSManagedObjectID</code> between threads/operations.</p> <p>Now, to get back to the corresponding managed object in an operation, I use <code>-existingObjectWithID:error:</code> thus:</p> <pre><code>Collection *owner = (Collection *)[localContext existingObjectWithID:self.containerId error:&amp;error]; </code></pre> <p>But what I get back is nil and <code>error</code> says this is an error #13300: <code>NSManagedObjectReferentialIntegrityError</code>.</p> <p>Here is what the documentation says about this error:</p> <pre><code>NSManagedObjectReferentialIntegrityError Error code to denote an attempt to fire a fault pointing to an object that does not exist. The store is accessible, but the object corresponding to the fault cannot be found. </code></pre> <p>Which is not true in my case: that object exists. Indeed, If I iterate through all instances of that <code>Collection</code> entity with an <code>NSFetchRequest</code>, I find it among them, and its <code>NSManagedObjectID</code> is exactly the one I passed to <code>-existingObjectWithID:error:</code>.</p> <p>Moreover, if I use <code>-objectWithID:</code> instead, I get a correct object back just fine.</p> <p>So there is something I'm missing. Here are a few additional observations/questions:</p> <ul> <li>"an object that does not exist": what it the meaning of "exist" in that sentence? "exist" where? It definitely "exists" in my Core Data store at that point.</li> <li>"the object corresponding to the fault cannot be found": what it the meaning of "found" in that sentence? "found" where? It definitely "be found" in my Core Data store at that point.</li> </ul> <p>So maybe I am missing something regarding what <code>existingObjectWithID:error:</code> does? The documentation says:</p> <pre><code>If there is a managed object with the given ID already registered in the context, that object is returned directly; otherwise the corresponding object is faulted into the context. [...] Unlike objectWithID:, this method never returns a fault. </code></pre> <p>This doesn't help my issue. I don't mind getting my object fully faulted, and not a fault. In fact, any fault within it will fire on the next code line when I access the object properties.</p> <ul> <li>What would be a realistic scenario leading to an <code>NSManagedObjectReferentialIntegrityError</code>?</li> </ul> <p>Thanks for any enlightenment.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload