Description
If using a Redis-OM Pydantic object as the input for a FastAPI route with a version greater than 0.112, you get the error shown below. NOTE: You don't even need to be trying to access the underlying RedisDB for this issue to occur, it is native to the Redis-OM wrapper around Pydantic.
To recreate for yourself:
# pyproject.toml
dependencies = [
"fastapi[standard]==0.113",
"redis-om>=0.3.3",
]
# main.py
from fastapi import FastAPI
from redis_om import JsonModel
class Name(JsonModel):
greet: str
app = FastAPI()
@app.post("/greet")
async def greet(name: Name):
# NOTE: You don't even need to interact with name to cause an error
return {"message": "Hello World"}
The error:
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'redis_om.model.model.ExpressionProxy'>. Set
arbitrary_types_allowed=True
in the model_config to ignore this error or implement__get_pydantic_core_schema__
on your type to fully support it.
If you got this error by calling handler() within__get_pydantic_core_schema__
then you likely need to callhandler.generate_schema(<some type>)
since we do not call__get_pydantic_core_schema__
on<some type>
otherwise to avoid infinite recursion.
For further information visit https://errors.pydantic.dev/2.10/u/schema-for-unknown-type