I think you may need to adjust it as follows:

  schema_txt = """
    {
        "name": "Test",
        "type": "record",
        "fields": [
            { "name": "Suit", "type": {"enum",
                "name": "Suit",
                "symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
              }
           }
        ]
    }
    """

On Mon, May 11, 2020 at 2:06 PM Charles Cazabon <
[email protected]> wrote:

> Hi,
>
> I'm using avro_python3-1.9.2.1 with Python 3.  I have a custom record
> schema
> that I would like to include an enum field in, but I get a
> SchemaParseException when I do so.
>
> For a minimal test case, using the example from the Python getting started
> guide as a complete schema is successful:
>
>     schema_txt = """
>     { "type": "enum",
>       "name": "Suit",
>       "symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
>     }
>     """
>
>     test_schema = avro.schema.parse(schema_txt)     # success
>
> However, if I create a record schema with such an enum as a member field
> (here
> the only field, but behaviour is the same with other fields present):
>
>     schema_txt = """
>     {
>         "name": "Test",
>         "type": "record",
>         "fields": [
>             { "type": "enum",
>               "name": "Suit",
>               "symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
>             }
>         ]
>     }
>     """
>
> ... then avro.schema.parse() fails with:
>
> Traceback (most recent call last):
>   File "./simple-schema.py", line 43, in <module>
>     test_schema = avro.schema.parse(schema_txt)
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 1244,
> in parse
>     return SchemaFromJSONData(json_data, names)
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 1215,
> in SchemaFromJSONData
>     return parser(json_data, names=names)
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 1143,
> in _SchemaFromJSONObject
>     other_props=other_props,
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 1022,
> in __init__
>     fields = make_fields(names=nested_names)
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 1134,
> in MakeFields
>     return tuple(RecordSchema._MakeFieldList(field_desc_list, names))
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 947,
> in _MakeFieldList
>     yield RecordSchema._MakeField(index, field_desc, names)
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 918,
> in _MakeField
>     names=names,
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 1215,
> in SchemaFromJSONData
>     return parser(json_data, names=names)
>   File ".../.venv/lib/python3.7/site-packages/avro/schema.py", line 1096,
> in _SchemaFromJSONString
>     % (json_string, sorted(names.names)))
> avro.schema.SchemaParseException: Unknown named schema 'enum', known
> names: ['Test'].
>
>
> What am I doing wrong?
>
> I've looked through the last six months of the avro users' list archive.
> The
> search function for the list appears to be offline so I haven't dug further
> than that.  Haven't found anything relevant with web searches either.
>
> Any help appreciated.
>
> Thanks,
>
> Charles
> --
> ------------------------------------------------------------------
> Charles Cazabon              <[email protected]>
> Software, consulting, and services available at http://pyropus.ca/
> ------------------------------------------------------------------
>


-- 

*Hisham ElSheshtawy*
Software Engineer, SparkMeter
Washington D.C., USA
*www.sparkmeter.io
<http://www.sparkmeter.io/?utm_source=email_signature&utm_medium=referral> *

*Have you heard about our New & Upcoming Products
<https://go.sparkmeter.io/new-product-announcements?utm_source=email_signature&utm_medium=referral>?*

Reply via email to