0

I have a Pydantic model which has an enum field. I'm trying to get the schema back but I get a runtime error which I suppose makes sense (I want a string type, but Pydantic is getting the Enum). How do I override this type?

>>> from pydantic_spark.base import SparkBase
>>> from enum import Enum

>>> class TestEnum(Enum):
>>>     SOMETHING = "something"
>>>     OTHER_THING = "something else"

>>> class TestModel(SparkBase):
>>>     thing: TestEnum

>>> my_model = TestModel(thing=TestEnum.SOMETHING)
>>> my_model.spark_schema()

RuntimeError: Unknown enum type: None
WhatAmIDoing
  • 198
  • 1
  • 1
  • 6
  • 1
    Does this answer your question? [Pydantic enum field does not get converted to string](https://stackoverflow.com/questions/65209934/pydantic-enum-field-does-not-get-converted-to-string) – Daniil Fajnberg Jul 06 '23 at 07:26

1 Answers1

0

Edit: found the answer here.

This works fine:

class MyEnum(str, Enum):
    ...
WhatAmIDoing
  • 198
  • 1
  • 1
  • 6