none
Azure Mobile table offline sync for Android doesn't handle conflicts RRS feed

  • Question

  • Hi all,

    I'm trying to use the offline sync stuff for Android. My main issue currently is the following scenario:

    1. Sync database
    2. Change local db
    3. Change server item (via a WebFrontend, which updates also the version flag, by inheriting EntityData)
    4. Push local changes

    The result is, that the server item is updated, also there should be a conflict. Debugging the stuff I realized that the "Version, UpdatedAt, CreatedAt" fields are not in the local db and therefore not provided in the patch request. I wonder how this could work? In .Net I have to subclass EntityData to handle the internal stuff for versioning. Why is this not needed for Android? Am I missing something?

    Thanks

    Edit:
    Adding the Version field to the Android DTO and DB seems to be needed. I'm wondering why there is not base class or some other predefined mechanisms for that. Also in the docs it's really hard to find something about this.

    Nevertheless, my sync handler is now called, but the status code is always null. This is my code for checking version conflicts.

    if (error.getStatusCode() != null && error.getStatusCode() == HttpURLConnection.HTTP_CONFLICT) {
    try {
    error.cancelAndUpdateItem();
    } catch (Throwable e) {
    throw new MobileServiceSyncHandlerException(e);
    }
    }

    Instead I only receive this ErrorMessage in the exception:
    com.microsoft.windowsazure.mobileservices.table.MobileServicePreconditionFailedExceptionJson


    • Edited by MonRoyals Thursday, June 23, 2016 11:35 AM
    Thursday, June 23, 2016 8:43 AM

Answers

  • From the update:

    You need a conflict handler.  PreconditionFailedException is a conflict - if you expand it out, you will get a server version of the record + a client version of the record.  The Xamarin/.NET HOWTO (which I know is not Android) has a good discussion of the process of conflict resolution here: https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-how-to-use-client-library/#optimisticconcurrency

    Note that even though it's .NET code, the principals - even down to the naming conventions for the Mobile Apps SDK - are the same, so you can still get a lot of value from reviewing the alternate version.

    • Proposed as answer by Swikruti Bose Saturday, June 25, 2016 3:18 PM
    • Marked as answer by MonRoyals Sunday, June 26, 2016 10:52 AM
    Friday, June 24, 2016 5:14 PM
    Moderator

All replies

  • No - you aren't missing anything. You need to manually add the required fields to your model.

    Version is required in the model for conflict resolution

    UpdatedAt is required in the model for incremental sync

    You should have both in your model.

    Technically, updatedAt is a timestamp and version is a byte[]

    • Proposed as answer by Swikruti Bose Saturday, June 25, 2016 3:18 PM
    Thursday, June 23, 2016 4:10 PM
    Moderator
  • From the update:

    You need a conflict handler.  PreconditionFailedException is a conflict - if you expand it out, you will get a server version of the record + a client version of the record.  The Xamarin/.NET HOWTO (which I know is not Android) has a good discussion of the process of conflict resolution here: https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-how-to-use-client-library/#optimisticconcurrency

    Note that even though it's .NET code, the principals - even down to the naming conventions for the Mobile Apps SDK - are the same, so you can still get a lot of value from reviewing the alternate version.

    • Proposed as answer by Swikruti Bose Saturday, June 25, 2016 3:18 PM
    • Marked as answer by MonRoyals Sunday, June 26, 2016 10:52 AM
    Friday, June 24, 2016 5:14 PM
    Moderator
  • Thanks a lot for the explanation!
    Friday, June 24, 2016 7:26 PM