{"record":{"id":"52b039ec84090f14","repo":"Significant-Gravitas/AutoGPT","slug":"failed-to-fetch-store-agents","errorCode":null,"errorMessage":"Failed to fetch store agents","messagePattern":"Failed to fetch store agents","errorType":"exception","errorClass":"DatabaseError","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/store/db.py","lineNumber":160,"sourceCode":"                sorted_by=sorted_by,\n                page=page,\n                page_size=page_size,\n            )\n            total_pages = (total + page_size - 1) // page_size\n\n        logger.debug(f\"Found {len(store_agents)} agents\")\n        return store_model.StoreAgentsResponse(\n            agents=store_agents,\n            pagination=store_model.Pagination(\n                current_page=page,\n                total_items=total,\n                total_pages=total_pages,\n                page_size=page_size,\n            ),\n        )\n    except Exception as e:\n        logger.error(f\"Error getting store agents: {e}\")\n        raise DatabaseError(\"Failed to fetch store agents\") from e\n    # TODO: commenting this out as we concerned about potential db load issues\n    # finally:\n    #     if search_term:\n    #         await log_search_term(search_query=search_term)\n\n\nasync def _fallback_store_agent_search(\n    *,\n    search_query: str | None,\n    featured: bool,\n    creators: list[str] | None,\n    category: str | None,\n    sorted_by: StoreAgentsSortOptions | None,\n    page: int,\n    page_size: int,\n) -> tuple[list[store_model.StoreAgent], int]:\n    \"\"\"Direct DB search fallback when hybrid search is unavailable or empty.\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/db.py#L142-L178","documentation":"A DatabaseError raised by the store listing query (get_store_agents) when any exception escapes the Prisma query / response-building path for the paginated store agents list. The original cause is chained ('from e') and logged as 'Error getting store agents'; the user-facing message is a generic fetch failure.","triggerScenarios":"GET store agents endpoints while the database is unreachable, the Prisma client is out of date with the schema (unknown column/relation), a pagination parameter causes an invalid query, or response model construction fails on unexpected nulls.","commonSituations":"DB outage or connection pool exhaustion; migrations run but prisma client not regenerated; schema drift between environments; malformed query params (negative page) reaching the ORM and erroring.","solutions":["Check backend logs for 'Error getting store agents' — the chained exception has the true cause.","If it's a schema/client mismatch, run database migrations and regenerate the Prisma client, then restart.","Verify DB connectivity and pool health from the backend host.","Sanitize/validate pagination and filter parameters before they reach the query."],"exampleFix":"# before\n# schema.prisma updated but client stale -> Unknown column errors\n# after\npoetry run prisma generate && poetry run prisma db push && restart backend","handlingStrategy":"retry","validationCode":"// Validate pagination inputs before listing\nif (!(page >= 1) || !(page_size >= 1 && page_size <= 100)) {\n  throw new RangeError('page must be >=1 and page_size in [1,100]');\n}","typeGuard":"const isValidPagination = (p: unknown) =>\n  typeof p === 'number' && Number.isInteger(p) && p >= 1;","tryCatchPattern":"try { return await getStoreAgents(filters); }\ncatch (e) {\n  if (e instanceof DatabaseError && /fetch store agents/.test(e.message)) {\n    return await withBackoff(() => getStoreAgents(filters), { tries: 2 }); // transient DB issues\n  }\n  throw e;\n}","preventionTips":["Clamp/validate query params at the API boundary before they reach Prisma.","Keep Prisma client regenerated in CI after every schema change.","Monitor DB pool saturation — listing endpoints are high-traffic."],"tags":["database","prisma","store","pagination"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}