full-stack-fastapi-template
full-stack-fastapi-template copied to clipboard
Exception in pydantic/schema.py when using Enum in Query - solved by upgrading dependencies
Just putting this here in case anyone else has this error and the fix
The case is when using an Enum as a query parameter e.g.
class Thing(str, Enum)
foo = "foo"
bar = "bar"
@router.get("/")
def read_job(thing: Optional[Thing]):
...
The error was an exception in pydantic.schema.py with a KeyError[<enum "Thing">}.
I couldn't work it out at all.
In the end it was a dependency thing. I bumped up the versions of fastapi and pydantic using poetry add fastapi@latest pydantic@latest, and the error disappeared.
Hope this helps someone else avoid spending hours trying to work out why something that should work does not.