I got BadChangeset Error

I got BadChangeset Error while creating a marker object.

let marker = Marker(value: [
        "_partition" : RealmConstants.commonRealmPartitionKey,
        "lat"        : realLat,
        "lng"        : realLng,
        "sakamichi"  : rowValues["sakamichi"] as! String,
        "category"   : rowValues["category"] as! String,
        "image"      : imageUrl,
        "postedBy"   : app.currentUser()!.id!
markerBody.relatedMarker = marker

var config = app.currentUser()?.configuration(partitionValue: RealmConstants.commonRealmPartitionKey)
config?.objectTypes = [Marker.self, MarkerBody.self, MemberTag.self]
let realm = try! Realm(configuration: config!)

try realm.write({ () -> Void in
        print("Marker Is Saved")

↓Error log


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



Write Summary:

  "Marker": {
    "inserted": [
  "MarkerBody": {
    "inserted": [

Realm Cocoa v10.0.0-beta.5

Platform Version:

Version 13.7 (Build 17H22)

I think partition value is correct, why did this error occur?

Shooting in the dark here but there could be a few causes. First though, markerBody object is undefined in your question so it’s possible that could be the cause.

Also, if you’re opening Realm for the first time, you need to do it with .asyncOpen to get the server and your local realm aligned. See Open a Synced Realm

Also force unwrapping optionals is not advised


protect your code by handling it in case it’s nil

guard let user = thisApp.currentUser() else {
    print("no user object, please log in")

Also, you’re specifying three object types and the last one doesn’t appear to be used and is undefined in the question so perhaps it doesn’t have a correct _partition

config?.objectTypes = [Marker.self, MarkerBody.self, MemberTag.self]

and since the error log is indicating successful writes of Marker and MarkerBody, I am going with the last one MemberTag.self being funky.

and… it could just be a random server error as we’ve seen those as well.

Thanks a lot, Jay. I checked all of causes you pointed out, but same error still occurred.
Next, I created another xcode project and build simplified application, then BadChangeset error while writing didn’t occur.
So, I uninstalled and reinstalled Realm, RealmSwift and application itself on a Simulator, then I finally added object successfully from main application.

@Shi_Miya This is likely due to the local realm state which is stored on the simulator. If at some previous time you had opened the realm with a different partitionKey value then you would likely get this error. Clearing the simulator by uninstalling the app or wiping the simulator is the best way to clear this.

1 Like

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