{"record":{"id":"e8c374aef1ff41ab","repo":"Significant-Gravitas/AutoGPT","slug":"invalid-page-number","errorCode":null,"errorMessage":"Invalid page number","messagePattern":"Invalid page number","errorType":"exception","errorClass":"DatabaseError","httpStatus":500,"severity":"warning","filePath":"autogpt_platform/backend/backend/api/features/store/db.py","lineNumber":530,"sourceCode":"            .replace(\"]\", \"\\\\]\")\n            .replace(\"'\", \"\\\\'\")\n            .replace('\"', '\\\\\"')\n            .replace(\";\", \"\\\\;\")\n            .replace(\"--\", \"\\\\--\")\n            .replace(\"/*\", \"\\\\/*\")\n            .replace(\"*/\", \"\\\\*/\")\n        )\n\n        where[\"OR\"] = [\n            {\"username\": {\"contains\": sanitized_query, \"mode\": \"insensitive\"}},\n            {\"name\": {\"contains\": sanitized_query, \"mode\": \"insensitive\"}},\n            {\"description\": {\"contains\": sanitized_query, \"mode\": \"insensitive\"}},\n        ]\n\n    try:\n        # Validate pagination parameters\n        if not isinstance(page, int) or page < 1:\n            raise DatabaseError(\"Invalid page number\")\n        if not isinstance(page_size, int) or page_size < 1 or page_size > 100:\n            raise DatabaseError(\"Invalid page size\")\n\n        # Get total count for pagination using sanitized where clause\n        total = await prisma.models.Creator.prisma().count(\n            where=prisma.types.CreatorWhereInput(**where)\n        )\n        total_pages = (total + page_size - 1) // page_size\n\n        # Add pagination with validated parameters\n        skip = (page - 1) * page_size\n        take = page_size\n\n        order: prisma.types.CreatorOrderByInput = (\n            {\"agent_rating\": \"desc\"}\n            if sorted_by == StoreCreatorsSortOptions.AGENT_RATING\n            else (\n                {\"agent_runs\": \"desc\"}","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/db.py#L512-L548","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","solutions":["Clamp the page in the caller: page = max(1, int(page)).","Make the API layer declare page: int = Field(ge=1) so FastAPI rejects bad values with 422 before the DB layer sees them.","Check the frontend pagination state — off-by-one where page index starts at 0."],"exampleFix":"// before\npage = currentPageIndex; // 0-based from UI\n// after\npage = max(1, currentPageIndex + 1);","handlingStrategy":"validation","validationCode":"const page = Math.max(1, Number.isFinite(pageParam) ? Math.trunc(pageParam) : 1);","typeGuard":"function isValidPage(page: unknown): boolean {\n  return Number.isInteger(page) && (page as number) >= 1;\n}","tryCatchPattern":null,"preventionTips":["Treat pagination as 1-based everywhere in the codebase.","Declare route params with ge=1 so FastAPI 422s bad values at the boundary.","Clamp page in the paginator component on prev/next handlers."],"tags":["validation","pagination","store"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}