Skip to content


Subversion checkout URL

You can clone with
Download ZIP


importFromObject crashes with bad_access #214

danielwischer opened this Issue · 9 comments

6 participants


Hi folks,

i really like magical record and used it in several projects.
Now i am building a facebook-app and one part is to load all friends from facebok and save it to coredata.

So i wanted to use magicalimport to import an array of friends.

But magicalrecord crashes in NSManagedObject+MagicalRecord.m in line 33. All attributes are named like the key in the dictionary, except the id attribute, which i defined in the userinfo section.

Any ideas on what to check? I read about setting the primarykeyattribute, but i dont have any relationships. Just one entity with 4 attributes.

Ask for further info if you need.



I'm having the same issue with iOS 6. Have you been able to fix it?


Same here.


I have the same problem when mapping 4 attributes via UserInfo dictionary and using this sample:

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {

    // Test data
    NSDictionary* data = @{@"id": @"1",
                           @"email": @"",
                           @"name": @"Barry",
                           @"gender": @"male"};

    User* test = [User importFromObject:data];
    NSLog(@"Test: %@", test);


When changing the code in NSManagedObject+MagicalDataImport.m from line 239 to this code, it works:

//    NSManagedObject *managedObject = [self MR_findFirstByAttribute:[primaryAttribute name] withValue:value inContext:context];
//    if (managedObject == nil) 
//    {
//        managedObject = [self MR_createInContext:context];
//    }

NSManagedObject *managedObject = [self MR_createInContext:context];

Found out what was the problem by debugging in MagicalRecord. It seems if you forget to set a "primary" key with the relatedByAttribute key in the user info dictionary it will crash.


So you'll just set one of the attributes (even if there are no relations) as "primary"?


@BarryBatser Can you help me out by expanding on your comment a little bit. The documentation around this is pretty thin.

How do I identify the "primary key"?

I have two models, User and Account and both use myID as the primary key. The User model has an accountID attribute on it. It is a one to many relationship (Account has many users). So what information do I need to put in "User Info" for:

  • User's myID attribute
  • Account's myID attribute
  • User's account relationship
  • Account's users relationship

Any help would be greatly appreciated! Thanks.


@ryanjm, can you take a look and see if #537 helps? I ran into something that sounds pretty similar a few days ago and submitted that PR.

@tonyarnold tonyarnold was assigned

Hey @tonyarnold. Thanks for the follow up. My issues was actually just not understanding how to properly get everything setup. Namely I was leaving out relatedByAttribute on the entity itself (and #447 also helped). I'm currently working through my models and making sure everything imports correctly.


There have been fixes for this issue applied to the upcoming 2.3 and 3.0 releases. Thanks for your patience, guys!

@tonyarnold tonyarnold closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.