importFromArray crashes when no relatedByAttribute is set #253

Closed
rickpastoor opened this Issue Sep 12, 2012 · 11 comments

Projects

None yet

6 participants

@rickpastoor

My array contains the following item:

{
id = 1;
name = Tuingereedschap;
radius = 0;
}

My model has the following fields:

parent_id
name
radius

On importing from this array, my application crashes, because I forgot to get the 'relatedByAttribute' user info on my entity with a cryptic error. It should at least give some kind of helpful error to help solve this mistake quickly.

@blackgold9
Member

Can you share the error generated?

@rickpastoor

It just crashes with a bad access, no further error message is given.

@aaronpeterson

I think this may be an issue of MR_findFirstByAttribute in MR_importFromObject:(id)objectData inContext:(NSManagedObjectContext *)context. The bad access occurs when NSAttributeDescription *primaryAttribute is nil (i.e. when you haven't set the "primary key" in the entity's User Info).

Maybe a good solution would be to MRLog the requirement that the entity define kMagicalRecordImportRelationshipLinkedByKey (currently "relatedByAttribute") in User Info in order to import. Either that, or if kMagicalRecordImportRelationshipLinkedByKey is not set in User Info, bypass the look-up/duplication check. I would prefer the former, personally :)

I love MagicalRecord, thanks.

@blackgold9
Member

Do you have a fix coded up you'd like to submit as a pull request? That would really speed things up here.

@aaronpeterson aaronpeterson added a commit to aaronpeterson/MagicalRecord that referenced this issue Sep 28, 2012
@aaronpeterson aaronpeterson Throw exception for missing relatedByAttribute
Re: issue #253 "importFromArray crashes when no relatedByAttribute is set"
6aa650c
@rickpastoor

You guys are awesome.

@aaronpeterson

I just got bitten by this again today. Found my own pull request. Aye...

@tonyarnold
Collaborator

I think I’ve just addressed this in #537 if any of you guys are still looking for a good fix to this issue.

@tonyarnold tonyarnold closed this Dec 29, 2013
@tonyarnold
Collaborator

I’m going to close this issue, as the tests attached to #537 verify that the problem is fixed (at least for what I experienced). Feel free to open a new issue if you’re seeing anything similar.

@zmcartor

👍 for this idea. A helpful error message would have saved lots of time.

@esttorhe

Sorry to be a party 💩er but I'm getting the same issue here and I think its due to the same lack of relatedByAttribute thing

@tonyarnold
Collaborator

@esttorhe any chance you could reduce the issues you're seeing down to a small test project? Also, can you verify that you've tried using the code in develop here and that the issue still occurs. Sorry to be all officious about it, but it can be very difficult to get to the bottom of some of the curlier import problems.

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