Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

MR_inThreadContext with the error. #325

gardenrabbit opened this Issue Nov 29, 2012 · 4 comments


None yet
2 participants

I think this method calls -(NSManagedObjectID *)objectID in the other thread, and collision occurs.

the error is below :
+MagicalRecord(ErrorHandling) defaultErrorHandler: Error Message: The operation couldn’t be completed. (Cocoa error 133000.)

I made category for NSManagedObjectID.

@interface NSManagedObjectID (MRT)

  • (NSManagedObject *)MRT_objectForCurrentThread;
    @implementation NSManagedObjectID (MRT)
  • (NSManagedObject *)MRT_objectForCurrentThread
    return [[NSManagedObjectContext MR_contextForCurrentThread] objectWithID:self];

tonyarnold commented Nov 29, 2012

Here's the description of the error you're seeing from Apple's documentation:

NSManagedObjectReferentialIntegrityError = 133000

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. Available in Mac OS X v10.4 and later. Declared in CoreDataErrors.h.

I'm pretty sure -(NSManagedObjectID *)objectID is not the problem here — it's safe to access this property across threads.

Your category uses objectWithID:…, which has different behaviour than existingObjectWithID:…, which is used in MR_inThreadContext:…:

/* returns the object for the specified ID if it is already registered, otherwise it creates a fault corresponding to that objectID.  It never returns nil, and never performs I/O.  The object specified by objectID is assumed to exist, and if that assumption is wrong the fault may throw an exception when used. */
- (NSManagedObject *)objectWithID:(NSManagedObjectID *)objectID;    

/* returns the object for the specified ID if it is already registered in the context, or faults the object into the context.  It might perform I/O if the data is uncached.  If the object cannot be fetched, or does not exist, or cannot be faulted, it returns nil.  Unlike -objectWithID: it never returns a fault.  */
- (NSManagedObject*)existingObjectWithID:(NSManagedObjectID*)objectID error:(NSError**)error NS_AVAILABLE(10_6, 3_0);
  • Is there further information available from the error?
  • Can you provide more context around what you're doing at the point this problem occurs?
  • How are you performing saves in your app?

thx for your comment.


tonyarnold commented Dec 14, 2012

Without further information, I can't provide any more advice. Feel free to re-open this issue if you can provide a bit more detail.

@tonyarnold tonyarnold closed this Dec 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment