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

Issues with 2.0.8? #297

Closed
andyfitter opened this Issue Nov 5, 2012 · 9 comments

Comments

Projects
None yet
5 participants

I pulled 2.0.8 today and it appears to have caused lots of problems, very similar to the issues we saw when state wasn't being maintained between different MOCs.

Haven't managed to track down exactly whats going on, but I'm seeing objects saved in one MOC not being updated in other MOCs.

Just wanted to flag this in case others are seeing it too. I've reverted to 2.0.7 and all seems fine again.

Member

blackgold9 commented Nov 5, 2012

in NSManagedObjectContext+MagicalRecord.m, all [self MR_makeContextObtainPermanentIds] line's were commented as part of debugging and not put back in. That's probably what's broken you. Uncommenting those lines will fix it in that case, and we'll get the repo fixed asap.

@blackgold9 blackgold9 closed this Nov 5, 2012

@blackgold9 blackgold9 reopened this Nov 5, 2012

stuffmc commented Nov 8, 2012

Could this be the reason why when using MR's stack any "save" isn't doing anything?! Not reporting an error either. Sounds like I'm on a "different" context, but I don't see why. Same store.

Member

blackgold9 commented Nov 8, 2012

Use savenestedcontexts

Sent from my mobile

On Nov 8, 2012, at 7:21 AM, StuFF mc notifications@github.com wrote:

Could this be the reason why when using MR's stack any "save" isn't doing
anything?! Not reporting an error either. Sounds like I'm on a "different"
context, but I don't see why. Same store.


Reply to this email directly or view it on
GitHubhttps://github.com/magicalpanda/MagicalRecord/issues/297#issuecomment-10191557.

stuffmc commented Nov 8, 2012

Wow. thanks. Interesting.

On Thu, Nov 8, 2012 at 4:53 PM, Stephen Vanterpool <notifications@github.com

wrote:

savenestedcontexts

Member

blackgold9 commented Nov 8, 2012

I'll explain a bit more when I get to a computer :)

Sent from my mobile

On Nov 8, 2012, at 8:02 AM, StuFF mc notifications@github.com wrote:

Wow. thanks. Interesting.

On Thu, Nov 8, 2012 at 4:53 PM, Stephen Vanterpool <notifications@github.com

wrote:

savenestedcontexts


Reply to this email directly or view it on
GitHubhttps://github.com/magicalpanda/MagicalRecord/issues/297#issuecomment-10193208.

This is definitely a bug; the commented calls to [moc MR_obtainPermanentIDsBeforeSaving] in NSManagedObjectContext+MagicalRecord.m are breaking parts of the context synchronization. Not quite clear why this got merged to master...

Contributor

fgarcia commented Nov 13, 2012

I am also having some difficulties with the new MR_save. In a moment of desperation I had to write this:

[[NSManagedObjectContext MR_rootSavingContext] MR_saveNestedContexts];
[[NSManagedObjectContext MR_context] MR_saveNestedContexts];
[[[NSManagedObjectContext MR_context] parentContext] MR_saveNestedContexts];
[[[[NSManagedObjectContext MR_context] parentContext] parentContext] MR_saveNestedContexts];

// again!
[[NSManagedObjectContext MR_context] save:nil];
[[[NSManagedObjectContext MR_context] parentContext] save:nil];
[[[[NSManagedObjectContext MR_context] parentContext] parentContext] save:nil];

None of the MR_saveNestedContexts lines solved the problem by itself. However I noticed something strange: the MR_saveNestedContexts are saving in the background. Therefore using them during applicationShouldTerminate: really cause a lot of trouble

I am not quite sure, but I always expected the MR_save to be blocking. Is MR_saveNestedContexts expected to be non-blocking?

the three last lines solve the problem because the default NSManagedObjectContext:save is blocking. Looking at the headers it is not so straight to find out which save functions from the categories are or are not blocking :(

Member

blackgold9 commented Nov 13, 2012

MR_save was altered to just save up one level to leave more flexibility in the developers hands for dealing with nested contexts. MR_save is just a convenience wrapper around the stock save method, and I didn't want it introducing extra behavior. We want save nested contexts to be non-blocking, because we want to keep the UI Thread as free as possible, since writing to disk can take a long time.
If you need to know when it's done, the MR_saveNestedContextsErrorHandler:callback: method can help there.

If you NEED it to block, you can use approaches such as

    dispatch_group_t group = dispatch_group_create();
    dispatch_group_enter(group);
    [context MR_saveNestedContextsErrorHandler:nil completion: ^{
      dispatch_Group_leave(group);
    }];

    dispatch_group_wait(group, DISPATCH_TIME_FOREVER);// Will block here until save is done.
Member

blackgold9 commented Nov 14, 2012

Develop now has obtaining perm ids re-enabled.

@blackgold9 blackgold9 closed this Nov 14, 2012

@tonyarnold tonyarnold added a commit to tonyarnold/MagicalRecord that referenced this issue Nov 18, 2012

@tonyarnold tonyarnold Add a blocking variant of the nested save method
As per the discussion in #297 — this is not what you'd normally want to
do, but there's a use-case for it.
a372137
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment