2

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?

andand
  • 17,134
  • 11
  • 53
  • 79

1 Answers1

0

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)
andand
  • 17,134
  • 11
  • 53
  • 79
  • Please tell me why, when checking, the last three commas do not give valid json. – Сергей Кох Dec 22 '22 at 17:26
  • Ah, it's not JSON, it's a python dictionary. Python allows trailing commas as shown. https://stackoverflow.com/questions/11597901/why-are-trailing-commas-allowed-in-a-list – andand Dec 22 '22 at 17:34