[BUG] pydantic.errors.PydanticUserError: `QueryParams` is not fully defined; you should define `ModelFilterSchema`, then call `QueryParams.model_rebuild()`.

Author: tomas-antal-icCreated Apr 20, 2026Updated Jun 4, 2026

Describe the bug There seems to be an issue with paginated and filtered endpoints.

While this works:

python
@api.get("/models", response=List[ModelSchema])
def list_models(request, filters: ModelFilterSchema = Query(...)) -> List[ModelSchema]:
    models = Model.objects.all()
    models = filters.filter(models)
    return models

And this also works:

python
@api.get("/models", response=List[ModelSchema])
@paginate
def list_models(request):
    models = Model.objects.all()
    return models

This one fails:

python
@api.get("/models", response=List[ModelSchema])
@paginate
def list_models(request, filters: ModelFilterSchema = Query(...)) -> List[ModelSchema]:
    models = Model.objects.all()
    models = filters.filter(models)
    return models

pydantic.errors.PydanticUserError: `QueryParams` is not fully defined; you should define `ModelFilterSchema`, then call `QueryParams.model_rebuild()`.

(Note, "Model" is just a placeholder here)

Versions:

  • Python version: 3.10
  • Django version: 5.2.13
  • Django-Ninja version: 1.6.2
  • Pydantic version: 2.12.5