Skip to content

RedisOM Pydantic objects cause POST request errors with FastAPI #679

Open
@aleexharris

Description

@aleexharris

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 call handler.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions