confluentinc/schema-registry

BACKWARD Compatibility Type does not support add optional field

ThinhLe30 opened this issue · 3 comments

Here is my case:
The registered old schema:

{
  "type": "record",
  "name": "user",
  "fields": [
    {
      "name": "name",
      "type": "string"
    },
    {
      "name": "favorite_number",
      "type": "int"
    }
  ]
}

The new schema which I have added a new optional field:

{
  "type": "record",
  "name": "user",
  "fields": [
    {
      "name": "name",
      "type": "string"
    },
    {
      "name": "favorite_number",
      "type": "int"
    },
    {
      "name": "favorite_color", // the optional field
      "type": "string",
      "default": "green"
    }
  ]
}

Then I use the rest-API to check compatibility:
According to these pages:
https://docs.confluent.io/platform/current/schema-registry/fundamentals/schema-evolution.html#backward-compatibility
https://docs.confluent.io/platform/current/schema-registry/develop/api.html#sr-api-compatibility

http://localhost:8081/compatibility/subjects/my-subject/versions/latest?verbose=true

and the request body:

{
  "schema": "[\"my.namespace.user\"]",
  "references": [
    {
      "name": "my.namespace.user",
      "subject": "seenow.dev.temp.my.namespace.user",
      "version": 1
    }
  ]
}

and the response:

{
    "is_compatible": false,
    "messages": [
        "{errorType:'MISSING_UNION_BRANCH', description:'The new schema is missing a type inside a union field at path '/0' in the old schema', additionalInfo:'reader union lacking writer type: RECORD'}",
        "{oldSchemaVersion: 1}",
        "{oldSchema: '[\"my.namespace.user\"]'}",
        "{compatibility: 'BACKWARD'}"
    ]
}

This seems weird because the BACKWARD compatibility already supports adding an optional field :((
Anybody can explain it to me?w

An optional field is a union of null and the type, such as "type": ["null", "string"]

already try it, it's the same response

old schema:

{
	"type": "record",
	"name": "user",
	"fields": [
		{"name": "name", "type": "string"},
		{"name": "favorite_number",  "type": "int"}
	]
}

new schema:

{
	"type": "record",
	"name": "user",
	"fields": [
		{"name": "name", "type": "string"},
		{"name": "favorite_number",  "type": "int"},
		{"name": "favorite_color", "type": ["null", "string"], "default": null}
	]
}

and the response:
image
:(((