MR_inContext fails because object has temporary ID #312

Closed
tonymillion opened this Issue Nov 17, 2012 · 6 comments

Comments

Projects
None yet
4 participants
@tonymillion

I just came across this, an object created & persisted in another context still had a temporary ID assigned to it, which caused MR_inContext to get a Cocoa 13300 Error.

I dont have the time to make a pull request at the moment (I've not even got a personal fork of Magical Record at the moment), but here is the code I did to fix this problem.

-(id)MR_inContext:(NSManagedObjectContext *)otherContext
{
    NSError *error = nil;

    if(self.objectID.isTemporaryID)
    {
        BOOL success = [self.managedObjectContext obtainPermanentIDsForObjects:@[self]
                                                                         error:&error];
        if (!success)
        {
            [MagicalRecord handleErrors:error];
        }
    }

    error = nil;

    NSManagedObject *inContext = [otherContext existingObjectWithID:[self objectID] error:&error];
    [MagicalRecord handleErrors:error];

    return inContext;
}
@casademora

This comment has been minimized.

Show comment
Hide comment
@casademora

casademora Nov 17, 2012

Member

Can you submit a pull request so you can be credited.

Thanks

Saul Mora
@casademora

On Nov 17, 2012, at 8:28 AM, Tony Million notifications@github.com wrote:

I just came across this, an object created & persisted in another context
still had a temporary ID assigned to it, which caused MR_inContext to get a
Cocoa 13300 Error.

I dont have the time to make a pull request at the moment (I've not even
got a personal fork of Magical Record at the moment), but here is the code
I did to fix this problem.

-(id)MR_inContext:(NSManagedObjectContext *)otherContext
{
NSError *error = nil;

if(self.objectID.isTemporaryID)
{
    BOOL success = [self.managedObjectContext

obtainPermanentIDsForObjects:@[self]

error:&error];
if (!success)
{
[MagicalRecord handleErrors:error];
}
}

error = nil;

NSManagedObject *inContext = [otherContext

existingObjectWithID:[self objectID] error:&error];
[MagicalRecord handleErrors:error];

return inContext;

}


Reply to this email directly or view it on
GitHubhttps://github.com/magicalpanda/MagicalRecord/issues/312.

Member

casademora commented Nov 17, 2012

Can you submit a pull request so you can be credited.

Thanks

Saul Mora
@casademora

On Nov 17, 2012, at 8:28 AM, Tony Million notifications@github.com wrote:

I just came across this, an object created & persisted in another context
still had a temporary ID assigned to it, which caused MR_inContext to get a
Cocoa 13300 Error.

I dont have the time to make a pull request at the moment (I've not even
got a personal fork of Magical Record at the moment), but here is the code
I did to fix this problem.

-(id)MR_inContext:(NSManagedObjectContext *)otherContext
{
NSError *error = nil;

if(self.objectID.isTemporaryID)
{
    BOOL success = [self.managedObjectContext

obtainPermanentIDsForObjects:@[self]

error:&error];
if (!success)
{
[MagicalRecord handleErrors:error];
}
}

error = nil;

NSManagedObject *inContext = [otherContext

existingObjectWithID:[self objectID] error:&error];
[MagicalRecord handleErrors:error];

return inContext;

}


Reply to this email directly or view it on
GitHubhttps://github.com/magicalpanda/MagicalRecord/issues/312.

@NealEhardt

This comment has been minimized.

Show comment
Hide comment
@NealEhardt

NealEhardt Jan 11, 2013

Contributor

Thank you! This fix really helped me.

Since I had to fork the repo, I went ahead and submitted a pull request. #378

Contributor

NealEhardt commented Jan 11, 2013

Thank you! This fix really helped me.

Since I had to fork the repo, I went ahead and submitted a pull request. #378

@tonymillion

This comment has been minimized.

Show comment
Hide comment
@tonymillion

tonymillion Jan 12, 2013

Dammit I submitted this as a pull request ages ago and it was rejected. I think I'm done helping MagicalRecord.

Dammit I submitted this as a pull request ages ago and it was rejected. I think I'm done helping MagicalRecord.

@tonymillion

This comment has been minimized.

Show comment
Hide comment

see #319

@tonyarnold

This comment has been minimized.

Show comment
Hide comment
@tonyarnold

tonyarnold Jan 12, 2013

Contributor

I'm not sure why your original pull request was closed without explanation, but I'll find out and we'll get this sorted out. It's possible that it was closed because the pull request was made against the master branch, and not develop where we merge in changes before release, but you should have been provided an explanation.

I should leave it at that… while I can understand your frustration over your fix not being merged, looking after this project is an unpaid gig, and there are only 3 of us on the team. Mistakes and oversights happen, and over the last month or so the focus was on fixing up problems with the save methods. The best we can do is apologise and do our best to prevent this from happening again.

Contributor

tonyarnold commented Jan 12, 2013

I'm not sure why your original pull request was closed without explanation, but I'll find out and we'll get this sorted out. It's possible that it was closed because the pull request was made against the master branch, and not develop where we merge in changes before release, but you should have been provided an explanation.

I should leave it at that… while I can understand your frustration over your fix not being merged, looking after this project is an unpaid gig, and there are only 3 of us on the team. Mistakes and oversights happen, and over the last month or so the focus was on fixing up problems with the save methods. The best we can do is apologise and do our best to prevent this from happening again.

@tonymillion

This comment has been minimized.

Show comment
Hide comment
@tonymillion

tonymillion Jan 12, 2013

That came out way grumpier than it should have done, so I apologise (this is after a few fairly involved twitter / app.net discussions). I shouldn't post before I've had my morning coffee.

side note: I dont actually use MagicalRecord, but I have looked at it in the past so any fixes I do post are usually just to help out :)

That came out way grumpier than it should have done, so I apologise (this is after a few fairly involved twitter / app.net discussions). I shouldn't post before I've had my morning coffee.

side note: I dont actually use MagicalRecord, but I have looked at it in the past so any fixes I do post are usually just to help out :)

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