Azure Mobile Service Offline Data Sync - The item provided was not valid

CharleyXIV

I am using Azure Mobile Service as a backend for an iOS app. I have set up everything to work with offline sync which allows me to view, add, or modify data even when there is no network connection. I am now into testing and I run into an error: "The item provided was not valid" when I try to synchronize data.

Here's what I am doing:

I add a new athlete to the syncTableWithName:@"Athlete" with this:

NSDictionary *newItem = @{@"firstname": @"Charles", @"lastname": @"Lambert", @"laterality" : @"Orthodox"};

        [self.athletesService addItem:newItem completion:^{
            NSLog(@"New athlete added");
        }];

Here's the addItem function:

-(void)addItem:(NSDictionary *)item completion:(CompletionBlock)completion
{
    // Insert the item into the Athlete table
    [self.syncTable insert:item completion:^(NSDictionary *result, NSError *error)
     {
         [self logErrorIfNotNil:error];

         // Let the caller know that we finished
         dispatch_async(dispatch_get_main_queue(), ^{
             completion();
         });
     }];
}

For now everything is fine and the item is in the syncTable. The problem is when I try to synchronize with the Azure Mobile Service. Here's the syncData function I am calling:

-(void)syncData:(CompletionBlock)completion
{   
    // push all changes in the sync context, then pull new data
    [self.client.syncContext pushWithCompletion:^(NSError *error) {
        [self logErrorIfNotNil:error];
        [self pullData:completion];
    }];
}

The pushWithCompletion gets me the error: "The item provided was not valid." and same for the pullData function that gets called after:

-(void)pullData:(CompletionBlock)completion
{
    MSQuery *query = [self.syncTable query];

    // Pulls data from the remote server into the local table.
    // We're pulling all items and filtering in the view
    // query ID is used for incremental sync
    [self.syncTable pullWithQuery:query queryId:@"allAthletes" completion:^(NSError *error) {
        [self logErrorIfNotNil:error];

        // Let the caller know that we finished
        dispatch_async(dispatch_get_main_queue(), ^{
            completion();
        });

    }];
}

I have tried inserting directly in the MSTable and that works fine. It's really when I am using the MSSyncTable that I run into this error. Although when I insert data manually in my database and that I synchronize my context I can fetch data and display within my UITableView.

Here is my Athlete table Lookin forward to see what you guys think about this. Thanks a lot!

I just edited my question thanks to @phillipv. When I add an item using NSDictionary just like I did I run into the error "The item provided was not valid". So I tried adding an item by first inserting it to my managedObjectContext and then calling:

NSDictionary *dict = [MSCoreDataStore  tableItemFromManagedObject:newAthlete];

I then I get the error when I try to sync: "The item provided did not have a valid id."

I feel like I am experiencing a circle.. :S

Shri

@Charley14, you can work around the bug by adding the following handler.

- (void)tableOperation:(nonnull MSTableOperation *)operation onComplete:(nonnull MSSyncItemBlock)completion
{
    NSMutableDictionary *rwItem = [NSMutableDictionary dictionaryWithDictionary:operation.item];

    // Temporary workaround
    [rwItem removeObjectsForKeys:@[ @"relationship1", @"relationship2"]];

    operation.item = rwItem;

    [operation executeWithCompletion:completion];
}

The tableOperation:onComplete: handler is simply removing keys that correspond to the relationships. You will have to replace 'relationship1', 'relationship2' in the code snippet with names of actual relationships in your application. Once the bug (https://github.com/Azure/azure-mobile-services/issues/779) is fixed, this workaround can be removed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Azure Mobile Service Offline Data Sync - The item provided was not valid

From Dev

Azure Mobile Service Offline Data Sync - Error on pullWithQuery

From Dev

UWP App With Azure Mobile Apps Backend Offline Data Sync Issue

From Dev

Using Azure App Service Mobile App or Azure Mobile Services Offline Sync SQLite (Xamarin, Ionic, PhoneGap)

From Dev

Azure > App Service > Mobile App > Offline Sync doesn't work on my Android (Xamarin.Forms)

From Dev

After doing PullAsync() on a table, I am unable to update the table data - Offline data sync in .Net Mobile service

From Dev

Which data types should a client model use for offline sync with the Azure mobile apps SDK?

From Dev

Azure offline sync of data from 1:n relationship in Android mobile app

From Dev

Azure Mobile Apps - An item to insert was not provided

From Dev

Azure Mobile App Offline SQLite Sync hanging on Initialize

From Dev

Offline sync with Azure Mobile Apps not working, database looks empty

From Dev

Client Side Transactions in Azure App Service Offline Sync

From Dev

investigate or compare the data being pushed and pulled in Azure Offline data Sync

From Dev

updating an existing item in an azure mobile service database

From Dev

Azure mobile service insert item with identity field

From Dev

How to trigger azure mobile service sync on other clients?

From Dev

Ionic Framework Data offline sync

From Dev

Including the created item ID in the response in Azure Mobile Service

From Dev

cordova azure offline data sync not working on multiple records entry after closing the app

From Dev

Azure offline sync local storage documentation

From Dev

How to sync Firebase offline data with online data

From Dev

Azure Mobile Service with Xamarin

From Dev

Count in Mobile Service Azure

From Dev

Azure Mobile Service with Xamarin

From Dev

Azure Mobile Service and Javascript

From Dev

ionic framework sync data and work offline

From Dev

MobileServiceClient.getPush() method not valid in Azure Mobile Service to Android, JS backend tutorial

From Dev

Windows Azure Service Mobile get All data from table

From Dev

Azure App Service Mobile App database synchronization failes if data is deleted

Related Related

  1. 1

    Azure Mobile Service Offline Data Sync - The item provided was not valid

  2. 2

    Azure Mobile Service Offline Data Sync - Error on pullWithQuery

  3. 3

    UWP App With Azure Mobile Apps Backend Offline Data Sync Issue

  4. 4

    Using Azure App Service Mobile App or Azure Mobile Services Offline Sync SQLite (Xamarin, Ionic, PhoneGap)

  5. 5

    Azure > App Service > Mobile App > Offline Sync doesn't work on my Android (Xamarin.Forms)

  6. 6

    After doing PullAsync() on a table, I am unable to update the table data - Offline data sync in .Net Mobile service

  7. 7

    Which data types should a client model use for offline sync with the Azure mobile apps SDK?

  8. 8

    Azure offline sync of data from 1:n relationship in Android mobile app

  9. 9

    Azure Mobile Apps - An item to insert was not provided

  10. 10

    Azure Mobile App Offline SQLite Sync hanging on Initialize

  11. 11

    Offline sync with Azure Mobile Apps not working, database looks empty

  12. 12

    Client Side Transactions in Azure App Service Offline Sync

  13. 13

    investigate or compare the data being pushed and pulled in Azure Offline data Sync

  14. 14

    updating an existing item in an azure mobile service database

  15. 15

    Azure mobile service insert item with identity field

  16. 16

    How to trigger azure mobile service sync on other clients?

  17. 17

    Ionic Framework Data offline sync

  18. 18

    Including the created item ID in the response in Azure Mobile Service

  19. 19

    cordova azure offline data sync not working on multiple records entry after closing the app

  20. 20

    Azure offline sync local storage documentation

  21. 21

    How to sync Firebase offline data with online data

  22. 22

    Azure Mobile Service with Xamarin

  23. 23

    Count in Mobile Service Azure

  24. 24

    Azure Mobile Service with Xamarin

  25. 25

    Azure Mobile Service and Javascript

  26. 26

    ionic framework sync data and work offline

  27. 27

    MobileServiceClient.getPush() method not valid in Azure Mobile Service to Android, JS backend tutorial

  28. 28

    Windows Azure Service Mobile get All data from table

  29. 29

    Azure App Service Mobile App database synchronization failes if data is deleted

HotTag

Archive