Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object is fetched again from Parse while saving the managed object context #42

Open
andreacremaschi opened this issue Apr 29, 2014 · 2 comments
Labels

Comments

@andreacremaschi
Copy link

Hi,

I am making my first experiments with PFIncrementalStore. I got a first test project up and running really quickly: I love the approach and really appreciate your work. Though I am struggling with a sync bug that I can't get rid of, and I don't understand if it is a bug or if I am approaching PFIncrementalStore the wrong way.

So, here is what is happening. I correctly retrieve some data from Parse, make some changes to the data, call save: on the main managedObjectContext. The issue is that sometimes the data is correctly saved, sometimes not, rolling back to the previous value.

I tried to debug this behavior: I added a symbolic breakpoint to -[PFQuery getObjectInBackgroundWithId:block:] and as I suspected this is being called twice:

  • directly by the library in -updateObject:fromRequest:inContext:error: override (this is correct)
  • indirectly by CoreData through newValuesForObjectWithID:withContext:error::
#2  0x00007fff8c8e589a in -[NSPersistentStoreCoordinator(_NSInternalMethods) _conflictsWithRowCacheForObject:withContext:andStore:] ()

As I read it: the call to save: immediately propagates the changes to the SQLite persistent store before the changes has been saved on the cloud. Of course CoreData find a conflict between the data state and the SQLite persistent store, so it asks PFIncrementalStore to solve it. PFIncrementalStore just fetch the data from Parse and overwrite the changes. So: the first operation that completes just wins.

If I am correct, maybe a solution could be to wait to propagate saves to the SQLite persistent store for the remote sync to complete.

@andreacremaschi
Copy link
Author

I should have mentioned the fact that my example project works on OSX (not iOS), and the fetches on Parse are driven by Cocoa bindings (through NSControllers subclasses). At first I thought it was because of the bindings, but I would tend to exclude it now.

@sbonami
Copy link
Owner

sbonami commented Apr 30, 2014

Hey @andreacremaschi, thanks for using PFIS! Your explanation and thorough walkthrough seem to pinpoint a bug, but I'll investigate and report back. I was also working on an OS X demo app as part of PR #14, care to push the app on a new branch so I can take a look? It'll provide an example and help with the debugging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants