Keep getting BadChangeset Error

@Ian_Ward
Error:

failed to validate upload changesets: instruction had incorrect partition value for key “username” (ProtocolErrorCode=212)
Partition:

barryf@ttienterprises.org

Write Summary:

{
  "foodHistory": {
    "updated": [
      "5f1d8688f78c2de5ba1c7119"
    ]
  },
  "waterConsumption": {
    "inserted": [
      "5f3fee386d749b3d166af8c1"
    ]
  }
}

SDK:
android v10.0.0-BETA.5
Platform Version:
8.1.0

@Barry_Fawthrop Hmmm, that doesn’t provide much more detail - I’d probably check the code used to specify the partitionKey value in a debugger

@Ian_Ward sadly I agree
Here is the android/kotlin code

val realm = Realm.getDefaultInstance()
realm.executeTransaction{ transaction ->
     val info = realm.createObject(waterConsumption::class.java, ObjectId.get())
     info.date     = date
      info.username = Globals.user.username
      info.ounces   = ounces
     Log.i("Realm-Access", "adding Water:   $info  ${info.username}  ")
     transaction.insert(info)
}

Here is Logcat output
I/Realm-Access: adding Water: waterConsumption = proxy[{_id:5f4024741b15025d47cbc155},{date:2020-08-21},{username:barryf@ttienterprises.org},{ounces:8.0}] barryf@ttienterprises.org

@Barry_Fawthrop Try statically setting it as a hardcoded string. Also, how did you open the realm

@Ian_Ward

val appID  = "r....p"
realmApp   = App(AppConfiguration.Builder(appID).build())

val credentials = Credentials.jwt(accessToken)
var realmUser: User?

realmApp.loginAsync(credentials) { it
     Log.i("REALM-ACCESS", "REALM-ACCESS           ${it.isSuccess}           ")
     if (it.isSuccess) {
          realmUser = realmApp.currentUser()
          val partition = Globals.user.username
          val config = SyncConfiguration.Builder(realmUser!!, partition).build()
          realm = Realm.getInstance(config)
          Realm.setDefaultConfiguration(config)
         . . .
         . . .

@Barry_Fawthrop Thanks - Have you tried statically setting the partition and username field as a hard-coded string rather than passing it in from Globals?

Also, do you get the same error with iOS?

-Ian

@Ian_Ward
No, iOS works well and I can save/create the record with iOS. iOS has no issues and no errors
this is purely creating a document with Android/Kotlin it creates the local document as reading the local DB has the new field. But it does NOT sync to Realm Server NOR to the Atlas Collection
and thus other devices.

I made username a static string still same error

BadChangeset Error Aug 23 9:41:17-04:00  1ms  SyncWrite --  [5f26c54b0cd4c10a409dcffb](https://realm.mongodb.com/groups/5c253dffc56c98059b6dafd0/apps/5f26c046a42e1c43ea410c9c/logs?user_id=5f26c54b0cd4c10a409dcffb)

[5f4271fddfc779089e764ca1](https://realm.mongodb.com/groups/5c253dffc56c98059b6dafd0/apps/5f26c046a42e1c43ea410c9c/logs?co_id=5f4271fddfc779089e764ca1)

Error:

failed to validate upload changesets: instruction had incorrect partition value for key "username" (ProtocolErrorCode=212)

Partition:

barryf@ttienterprises.org

Thanks

Barry

@Barry_Fawthrop Strange - would you be willing to send me the app so I could repro and figure out what is going wrong? You can email me at ian.ward@mongodb.com

Hi There,

I am also getting lots of these errors when just opening a realm and reading an object in node.

Its especially strange since the console output from realm (its noisy) shows the following during the read:

Connection[2]: Session[2]: Received: ERROR(error_code=212, message_size=22, try_again=0)

But in the runtime the object/realm is seemingly valid and throws no errors.
If you try to make changes in a write block, no changes get committed and the last message AFTER you’re all done is:

[
  'Open Error - error',
  {
    name: 'Error',
    message: 'Bad changeset (UPLOAD)',
    isFatal: true,
    category: 'realm::sync::ProtocolError',
    code: 212,
    userInfo: {}
  }
]

I’m using dev mode, not manually managing _partition and leaving that up to realm to manage internally and the schema has not changed on the client side.

I don’t seem to get consistent behaviour on every run either. I’m pulling my hair out.

Any progress on what is causing these issues?

1 Like

I think I’m running into a similar issue here, but with Android. I’m using a key “author” as the partition value. When I log the author of every object I’m trying to synch, they all match the partition. but

I still get this on the server logs. I’ve tried terminating synch and restarting, wiping the simulator, etc.

Error:
failed to validate upload changesets: instruction had incorrect partition value for key “author” (ProtocolErrorCode=212)

Partition:
5f4c4cca4ae5e33550354328

Write Summary:
{

  • “Recipe”: {*
  • “inserted”: [*
  •  "5f4c4cdd9933dd503e2804d1"*
    
  • ]*
  • }*
    }
    SDK:
    android v10.0.0-BETA.5

Platform Version:
11

Is there any timeline on the added logging mentioned by @nirinchev ? This would be very helpful.

@Ryan_Goodwin Can you share your android model and the code for inserting an object? Notably, I’m interested in seeing if you’re using createObject or copyToRealm.

I have tried both neither worked, according to @Ian_Ward there is a fix being pushed to production that is going to address this.

Here are the models. partition key is ‘author’.

open class Recipe : RealmObject() {
    @PrimaryKey open var _id: ObjectId? = ObjectId()
    open var title: String? = null
    open var author: String = ""
    var ingredients: RealmList<Ingredient> = RealmList()
    var directions: RealmList<Direction> = RealmList()
}

open class Direction : RealmObject() {
    @PrimaryKey open var _id: ObjectId = ObjectId()
    open var text: String = ""
    open var author: String = ""
}

open class Ingredient : RealmObject() {
    @PrimaryKey open var _id: ObjectId = ObjectId()
    open var name: String? = ""
    open var author: String = ""
}

I’m using createObject. This is the heart of the main function I’m using to create recipes.

realm.executeTransaction { _ ->
            try {
                val auth = app.currentUser()?.id ?: ""
                recipe.title = title
                recipe.author = auth

                if(directionView) {
                    recipe.directions.deleteAllFromRealm()

                    for (i in textBoxContents) {
                        val dir = realm.createObject<Direction>(ObjectId())
                        dir.text = i
                        dir.author = auth
                        recipe.directions.add(dir)
                    }
                }
                else {
                    recipe.ingredients.deleteAllFromRealm()

                    for (i in textBoxContents) {
                        val ing = realm.createObject<Ingredient>(ObjectId())
                        ing.name = i
                        ing.author = auth
                        recipe.ingredients.add(ing)
                    }
                }

            } catch (e: Exception) {
                e.printStackTrace()
            }
        }

My final experiment last night was to fall back to hard coded strings for the ‘author’ key. That change did restore synch. My next thought is that the problem is in the lag between creating the object and setting the author. Do I need to custom initialize the model to set an author on creation?

Thanks for the :eyes: @nirinchev

Hey All - we just merged a serverside fix for this in production - give it a try now.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.