full-stack-fastapi-template icon indicating copy to clipboard operation
full-stack-fastapi-template copied to clipboard

Exception in pydantic/schema.py when using Enum in Query - solved by upgrading dependencies

Open ttamg opened this issue 4 years ago • 0 comments

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.

ttamg avatar Mar 13 '21 11:03 ttamg