Skip to content

[BUG] Endpoint with query schema crashes when paginated and from __future__ import annotations import included #1424

Description

@jjnesbitt

Apologies for the lengthy title.

Describe the bug
I get the following error on application start:

NameError: name 'MySchema' is not defined

If the following conditions are met:

  1. An endpoint function is defined with the paginate decorator
  2. There is an argument to the function that is a user defined query param schema (Query[MySchema])
  3. The from __future__ import annotations import is present in the file

If any of these three things are excluded, the bug does not occur.

Versions (please complete the following information):

  • Python versions tested: 3.11, 3.12, 3.13
  • Django version: 5.1.6
  • Django-Ninja version: 1.3.0
  • Pydantic version: 2.10.6

Here is an MRE:

from __future__ import annotations

from ninja import NinjaAPI, Query, Schema
from ninja.pagination import PageNumberPagination, paginate


class MySchema(Schema):
    foo: str


api = NinjaAPI()


@api.get("/endpoint_path", response=list[int])
@paginate(PageNumberPagination)
def atpath(
    request,
    params: Query[MySchema],
):
    return []

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions