Significant-Gravitas/AutoGPT · warning · DatabaseError

Invalid page number

Error message

Invalid page number

What it means

Raised in get_store_creators when the page parameter is not an int or is less than 1. It is a defensive type/range check executed before the Prisma count query. Although it is raised as DatabaseError, no database error occurred — the caller passed an invalid pagination value (0, negative, or a non-integer coerced by query parsing).

Source

Thrown at autogpt_platform/backend/backend/api/features/store/db.py:530

            .replace("]", "\\]")
            .replace("'", "\\'")
            .replace('"', '\\"')
            .replace(";", "\\;")
            .replace("--", "\\--")
            .replace("/*", "\\/*")
            .replace("*/", "\\*/")
        )

        where["OR"] = [
            {"username": {"contains": sanitized_query, "mode": "insensitive"}},
            {"name": {"contains": sanitized_query, "mode": "insensitive"}},
            {"description": {"contains": sanitized_query, "mode": "insensitive"}},
        ]

    try:
        # Validate pagination parameters
        if not isinstance(page, int) or page < 1:
            raise DatabaseError("Invalid page number")
        if not isinstance(page_size, int) or page_size < 1 or page_size > 100:
            raise DatabaseError("Invalid page size")

        # Get total count for pagination using sanitized where clause
        total = await prisma.models.Creator.prisma().count(
            where=prisma.types.CreatorWhereInput(**where)
        )
        total_pages = (total + page_size - 1) // page_size

        # Add pagination with validated parameters
        skip = (page - 1) * page_size
        take = page_size

        order: prisma.types.CreatorOrderByInput = (
            {"agent_rating": "desc"}
            if sorted_by == StoreCreatorsSortOptions.AGENT_RATING
            else (
                {"agent_runs": "desc"}

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Clamp the page in the caller: page = max(1, int(page)).
  2. Make the API layer declare page: int = Field(ge=1) so FastAPI rejects bad values with 422 before the DB layer sees them.
  3. Check the frontend pagination state — off-by-one where page index starts at 0.

Example fix

// before
page = currentPageIndex; // 0-based from UI
// after
page = max(1, currentPageIndex + 1);
Defensive patterns

Strategy: validation

Validate before calling

const page = Math.max(1, Number.isFinite(pageParam) ? Math.trunc(pageParam) : 1);

Type guard

function isValidPage(page: unknown): boolean {
  return Number.isInteger(page) && (page as number) >= 1;
}

Prevention

When it happens

Trigger: GET /store/creators?page=0, ?page=-1, or ?page=abc (depending on FastAPI coercion this may 422 first; direct service-layer calls with None/str hit this branch).

Common situations: Frontend computing current_page from an index variable that starts at 0; passing an empty string that defaults to 0; a paginator component that decrements below 1 on the first page.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/e8c374aef1ff41ab. Report an issue: GitHub.