Skip to content

Avro Schema references no longer work in 2.8.2 #1940

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

Closed
tomroberts92 opened this issue Mar 12, 2025 · 2 comments
Closed

Avro Schema references no longer work in 2.8.2 #1940

tomroberts92 opened this issue Mar 12, 2025 · 2 comments

Comments

@tomroberts92
Copy link

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

@rayokota
Copy link
Member

Thanks @tomroberts92 , I'll take a look

@rayokota
Copy link
Member

@tomroberts92 , when you register the schema, you need to specify the name as "example.MyReference"

"references":[{"name":"example.MyReference","subject":"example.MyReference","version":1}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants