Realm Sync validate upload changesets error

Hi, I’m getting this error with realm sync that it’s ending the sync session before it can sync the data. Error: ending session with error: failed to validate upload changesets: field "field_name" in table "table_name" should have link type "objectId" but payload type is "Null" (ProtocolErrorCode=212).

The field specified is a relationship field, which makes the field not required, but I still have the error coming in. A field that is not required can be nullable? Is that correct or am I missing something?

Hi @Rossicler_Junior,

That error implies that you are generating a link to a table with a required primary key, but the primary key in your link is null so it fails schema validation. Is this error coming from a device session? Or do you encounter this error when sync is trying to ingest your MongoDB data?

I can only see this error in the realm app logs, not on client side. The error type is either Sync -> Session End or Sync -> Write with status BadChangeset Error

Just to make sure if I understand what you’re saying, if the relationship field is null it will generate this error?

Let me give you an example of a realm scenario. I have a schema “schema_1”, this schema has a field called “media”, which is a relationship to a schema called “media”, pointing to “_id” primary key field.
On my “schema_1” I have some entries with the media field being the ObjectId of a media _id, and some of them are null. So the null values are a problem? Even if “media” field is not required?

Screenshot of the media field in the realm schema.

if the relationship field is null it will generate this error?

The link consists of two components: a table and primary key. So the link can be non-null, while the primary key is null.

In any case, that error should never appear for writes originating in MongoDB, so it appears there’s a bug somewhere. Can you share the value of the media field in the document that is triggering the bad changeset error? The Sync --> Write log with the BadChangeset Error should contain a Write Summary section that you can use to determine which document triggered the error.

Feel free to follow up in a DM if you don’t want to share the data publicly here!

I don’t see any additional log that indicates the document which triggered the error. But I think I found the issue and fixed it. I found some entries in my schema_1 with the media field as undefined instead of null. I manually changed them to null, terminated device sync and started again, so far it’s working and no more errors.

Last time this happened it also worked for some time then the error came in, if the error persists I will come back here to update you about more details. Thanks for the help!

Got it - I was able to reproduce the error you’re seeing with an undefined value, so we’ll have to fix that on our end. In the meantime, you can avoid it by using null values instead of undefined as you identified!

1 Like

Yep, already done the changes to avoid undefined and use null instead. Thank you

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