Skip to content

Avro Schema references no longer work in 2.8.2 #1940

Closed
@tomroberts92

Description

@tomroberts92

Upgrading to 2.8.2 for 2.8.0 has resulted in Avro schema references no longer working.

As an example:

{
  "name": "MyReference",
  "namespace": "example",
  "type": "record",
  "fields": [
    {
        "name": "a_string",
        "type": "string"
    },
    {
        "name": "an_int",
        "type": "int"
    }
  ]
}

registered under the subject example.MyReference which is referenced by the schema

{
    "type": "record",
    "name": "TestSchema",
    "fields" : [
        {"name": "reference",
        "type": "example.MyReference",
        "version": 1}
    ]
}

registered under the subject test-value
The schemas register correctly register. Going to http://localhost:8085/subjects/test-value/versions/1 gives

{"subject":"test-value","version":1,"id":7,"references":[{"name":"reference","subject":"example.MyReference","version":1}],"schema":"{\"type\":\"record\",\"name\":\"TestSchema\",\"fields\":[{\"name\":\"reference\",\"type\":\"example.MyReference\",\"version\":1}]}"}

Using 2.8.0 I can produce a message with this no issue.

❯ poetry run python src/produce.py
2025-03-12 16:31:27 - Producer - INFO - Record successfully produced to test partition [0] at offset 0

{
	"reference": {
		"a_string": "foo",
		"an_int": 5
	}
}

However, after updating to 2.8.2 I get the following error:

❯ poetry run python src/produce.py
Traceback (most recent call last):
  File "fastavro/_schema.pyx", line 537, in fastavro._schema._parse_schema_with_repo
  File "fastavro/_schema.pyx", line 173, in fastavro._schema.parse_schema
  File "fastavro/_schema.pyx", line 407, in fastavro._schema._parse_schema
  File "fastavro/_schema.pyx", line 475, in fastavro._schema.parse_field
  File "fastavro/_schema.pyx", line 267, in fastavro._schema._parse_schema
fastavro._schema_common.UnknownType: example.MyReference

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/src/producer.py", line 75, in _get_serializer
    return AvroSerializer(self.schema_registry_client, schema.schema, conf=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.venv/lib/python3.11/site-packages/confluent_kafka/schema_registry/avro.py", line 284, in __init__
    parsed_schema = self._get_parsed_schema(schema)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.venv/lib/python3.11/site-packages/confluent_kafka/schema_registry/avro.py", line 384, in _get_parsed_schema
    parsed_schema = parse_schema_with_repo(
                    ^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.venv/lib/python3.11/site-packages/confluent_kafka/schema_registry/avro.py", line 631, in parse_schema_with_repo
    return load_schema("$root", repo=repo)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "fastavro/_schema.pyx", line 509, in fastavro._schema.load_schema
  File "fastavro/_schema.pyx", line 517, in fastavro._schema._load_schema
  File "fastavro/_schema.pyx", line 541, in fastavro._schema._parse_schema_with_repo
  File "fastavro/_schema.pyx", line 517, in fastavro._schema._load_schema
  File "fastavro/_schema.pyx", line 537, in fastavro._schema._parse_schema_with_repo
  File "fastavro/_schema.pyx", line 173, in fastavro._schema.parse_schema
  File "fastavro/_schema.pyx", line 263, in fastavro._schema._parse_schema
TypeError: argument of type 'NoneType' is not iterable

This seems to be related to the changes that fixed type unions here. #1928

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions