Start a new topic
Answered

Calling PushAsync or Sync does not push up local data

I am starting with a few entities in my collection. I delete one entity and then sync like this...

 KinveyDeleteResponse kdr = await _dataStore.RemoveAsync(id.ToString());

await SyncData();

 The call to Sync Data does not actually sync the online data store to the device store and push up the delete.

I then try and retrieve my collection of entities like this... 

PushDataStoreResponse<KCCCInventoryItem> dsr = await _dataStore.PushAsync();
OR
await _dataStore.SyncAsync();

PullDataStoreResponse<KCCCInventoryItem> dsr = await _dataStore.PullAsync();

return dsr.PullEntities;

 But I get this error ever time.


"Kinvey.KinveyException: Cannot pull until all local changes are pushed to the backend.Call store.push() to push pending local changes, or store.purge() to clean local changes.Refer to the documentation on DataStore types for proper usage of the DataStore caching and syncing APIs.

  at Kinvey.DataStore`1+<PullAsync>c__async9[T].MoveNext ()


So I am confused. I have called Sync (which is a push then a pull) and Push and yet my local changes still will not sync. And am I correct in seeing that there is no method on the DataStore called Push, only PushAsync? If so, then that is a misleading error message. What am I doing wrong? Also, I have no issue creating and pushing a new item like this...

await _dataStore.SaveAsync(item);

await SyncData();

 




Best Answer

Sevren,


When delete response has a count of 0, that means delete operation failed. Are you able to see the updated changes in the Kinvey console?


Please take a look at sample apps for better understanding of how to use Kinvey features.


Thanks,

Pranav

Kinvey


Answer

Sevren,


When delete response has a count of 0, that means delete operation failed. Are you able to see the updated changes in the Kinvey console?


Please take a look at sample apps for better understanding of how to use Kinvey features.


Thanks,

Pranav

Kinvey

Hi Pranav, so I started by calling Push first as that is how all the example are and that fails. I just went back and tried again with no success. To give more information, when I attempt the delete the delete response has a count of 0, does that mean that the delete was unsuccessful? Despite that, when I go to pull the items again using this code...

            try
            {
                if (!Client.SharedClient.IsUserLoggedIn())
                {
                    await User.LoginAsync(user, pass);
                }

                int syncStoreCount = _dataStore.GetSyncCount();

                if (syncStoreCount > 0)
                {
                    PushDataStoreResponse<KCCCInventoryItem> dsr  = await _dataStore.PushAsync();

                    await _dataStore.SyncAsync();

                    System.Diagnostics.Debug.WriteLine($"Push good - pulling - Push Count {dsr.PushCount} - Exc {dsr.KinveyExceptions} ");
                }

                PullDataStoreResponse<KCCCInventoryItem> dsr = await _dataStore.PullAsync();

                return dsr.PullEntities;

            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine($"Getting items FAILED {e}");
                return null;
            }

  I get a push count of 1, so I assume it thinks that it pushed 1 item, but then I immediately get this error every time, suggesting that the delete was successful, "Cannot pull until all local changes are pushed to the backend.Call store.push() to push pending local changes, or store.purge() to clean local changes." So I cannot tell if the delete is successful or not.

Sevren,

Please use "push()" to push entities modified in local storage to the backend. After that you can call "sync()". Did you get any issue while deleting an entity? You can call purge on the datastore, which will remove all pending writes from the queue. The failed entity remains in your local cache, but the library will not attempt to push it again to the backend. Check http://devcenter.kinvey.com/xamarin/guides/datastore#pushFailures.

Let me know how it goes.

Thanks,
Pranav

 

Login or Signup to post a comment