Data Import breaks on relationships. #591

Closed
ryanjm opened this Issue Oct 17, 2013 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

ryanjm commented Oct 17, 2013

Occassionally (not every time) I get an error on NSManagedObject+MagicalDataImport.m Line 168 (I'm on the develop branch).

id relatedObjectData = [relationshipData valueForKeyPath:lookupKey];

But I'm not sure why it is getting here. Hopefully I'm not too verbose, but in hope of making this clear, let me explain what is happening with my code / MR.

I'm calling MR_importFromArray:inContext: for my entity called InspectionFormStructure. And the array looks like:

(lldb) po resources
$2 = 0x1dc6b200 <__NSCFArray 0x1dc6b200>(
{
    "created_at" = "2013-09-30T12:46:52-06:00";
    "deleted_at" = "<null>";
    id = 140945;
    "inspection_form_id" = 31048;
    "schedule_id" = "<null>";
    "structure_id" = 6539;
    "updated_at" = "2013-09-30T12:46:52-06:00";
},
...

This goes through the normal import process, but the part that I think is messing up is when it starts importing relationships.

    [self MR_setRelationships:relationships forKeysWithObject:objectData withBlock:relationshipBlock];

The first time it is called, it looks good. relationships are the ones for InspectionFormStructure(as expected) and theobjectData` is the one dictionary in the array. So far, so good.

But then establishRelationship is called (Line 194).

establishRelationship(relationshipInfo, relatedObjectData);

The relationshipInfo is the NSRelationshipDescription of inspectionForm and the relatedObjectData is just the id (31048).

This calls the block which then calls setRelationshipBlock (side note: these block calls are sometimes hard to follow since there are so many of them). This then goes to:

[relatedObject MR_importValuesForKeysWithObject:localObjectData];

At this point relatedObject is an empty InspectionForm and the id (myID) isn't set. And I'm not sure how it expected so importValuesForKeysWithObject when localObjectData is just a number. And this is what causes the error. It goes through to MR_performDataImportFromObject:relationshipBlock: then to MR_setRelationships:forKeysWithObject:withBlock: and then fails trying to look up a relationship (lookupKey) on an number (relationshipData).

Am I doing something wrong, or is there something missing in the relationship building?

Again, this only happens occassionally (which I think has to do with my threading issue which I'm trying to figure out).

Any help would be appreciated. Let me know if there is something I can do to help.

Contributor

tonyarnold commented Apr 8, 2014

Given the age of this issue, and the volume of issues we have to work through, I've decided to close this alongside a number of other older issues.

If you can still replicate the issue under the latest in-development version of MagicalRecord (3.0 at the time of writing), please feel free to re-open and one of @magicalpanda/team-magicalrecord will take another look. Thanks!

@tonyarnold tonyarnold closed this Apr 8, 2014

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