Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avro schema evolution not working with Union type and null default #4120

Closed
jrkinley opened this issue Mar 28, 2022 · 1 comment · Fixed by #4129
Closed

Avro schema evolution not working with Union type and null default #4120

jrkinley opened this issue Mar 28, 2022 · 1 comment · Fixed by #4129
Labels
area/schema-registry Schema Registry service within Redpanda kind/bug Something isn't working

Comments

@jrkinley
Copy link

Version & Environment

Redpanda v2.11.10

What went wrong?

Adding a new field to an Avro schema with a default value of null should be backwards compatible (note that None in Python is correctly translated to null by json.dumps):

{
  "name": "value2",
  "type": ["null", "int"],
  "default": None
}

But the schema registry rejects the new version of the schema with:

{
  "error_code": 409,
  "message": "Schema being registered is incompatible with an earlier schema for subject \"{sensor-value}\""
}

The subject's compatibility mode is set to BACKWARD and Python's Avro schema compatibility checks pass ok:

from avro.schema import parse
from avro.compatibility import ReaderWriterCompatibilityChecker

is_compatible = ReaderWriterCompatibilityChecker().get_compatibility(
  parse(json.dumps(sensor_schema_v2)),
  parse(json.dumps(sensor_schema))
)
print(f"Schemas compatible: {is_compatible.compatibility}")

What should have happened instead?

The schema registry should accept the new schema version because the additional field is backward compatible.

How to reproduce the issue?

schema-registry.txt

@jrkinley jrkinley added kind/bug Something isn't working area/schema-registry Schema Registry service within Redpanda labels Mar 28, 2022
@jrkinley jrkinley changed the title Avro schema evolution not working with Union type with default Avro schema evolution not working with Union type and null default Mar 28, 2022
@jrkinley jrkinley changed the title Avro schema evolution not working with Union type and null default Avro schema evolution not working with Union type and null default Mar 28, 2022
BenPope added a commit to BenPope/redpanda that referenced this issue Mar 28, 2022
For Avro, nil type in a union is supported for backwards compatibility,
if it's also the default. The default value must be of the type of the
first type in the union.

This change allows that.

Fixes redpanda-data#4120
BenPope added a commit to BenPope/redpanda that referenced this issue Mar 28, 2022
For Avro, nil type in a union is supported for backwards compatibility,
if it's also the default. The default value must be of the type of the
first type in the union.

This change allows that.

Fixes redpanda-data#4120

(cherry picked from commit 2cfa559)
@andrewhsu
Copy link
Member

/backport v21.11.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema-registry Schema Registry service within Redpanda kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants