Fastavro fails to parse Avro schema with enum

1.1k Views Asked by At

I have the following code block:

import fastavro

schema = {
    "name": "event",
    "type": "record",
    "fields": [{"name": "event_type", "type": "enum", "symbols": ["START", "STOP"]}],
}

checker = fastavro.parse_schema(schema=schema)

Upon running it, it generates the following error:

Traceback (most recent call last):
  File ".\test_schema.py", line 7, in <module>
    checker = fastavro.parse_schema(schema=schema)
  File "fastavro\_schema.pyx", line 121, in fastavro._schema.parse_schema
  File "fastavro\_schema.pyx", line 322, in fastavro._schema._parse_schema
  File "fastavro\_schema.pyx", line 381, in fastavro._schema.parse_field
  File "fastavro\_schema.pyx", line 191, in fastavro._schema._parse_schema
fastavro._schema_common.UnknownType: enum

I'm running fastavro 1.7.0, on Windows 10, and python 3.8.8. I have had similar problems on Linux (RHEL 8) using python 3.10.

Based on the Avro documentation for enumerated types, the schema seems correct, but fastavro fails to recognize the enum type. Am I doing something wrong here, or does fastavro 1.7.0 not support Avro 1.9 enumerations?

1

There are 1 best solutions below

2
On

Looks like the schema is not correctly formed. After some additional checking, the following works:

import fastavro

schema = {
    "name": "event",
    "type": "record",
    "fields": [
        {
            "name": "event_type",
            "type": {
                "type": "enum",
                "name": "event_type_enums",
                "symbols": ["START", "STOP"],
            },
        }
    ],
}

checker = fastavro.parse_schema(schema=schema)