{"record":{"id":"ec0a3e4c63a56056","repo":"Significant-Gravitas/AutoGPT","slug":"failed-to-fetch-agent","errorCode":null,"errorMessage":"Failed to fetch agent","messagePattern":"Failed to fetch agent","errorType":"exception","errorClass":"DatabaseError","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/store/db.py","lineNumber":388,"sourceCode":"                    \"isAvailable\": True,\n                    \"isDeleted\": False,\n                },\n                include={\"AgentGraph\": {\"include\": AGENT_GRAPH_INCLUDE}},\n            )\n        )\n\n        if not store_listing_version or not store_listing_version.AgentGraph:\n            raise NotFoundError(\n                f\"Store listing version {store_listing_version_id} not found\",\n            )\n\n        return (GraphModelWithoutNodes if hide_nodes else GraphModel).from_db(\n            store_listing_version.AgentGraph\n        )\n\n    except Exception as e:\n        logger.error(f\"Error getting agent: {e}\")\n        raise DatabaseError(\"Failed to fetch agent\") from e\n\n\nasync def get_store_agent_by_version_id(\n    store_listing_version_id: str,\n) -> store_model.StoreAgentDetails:\n    \"\"\"Get agent details from the StoreAgent view (APPROVED agents only).\n\n    See also: `get_store_agent_details_as_admin()` which bypasses the\n    APPROVED-only StoreAgent view for admin preview of pending submissions.\n    \"\"\"\n    logger.debug(f\"Getting store agent details for {store_listing_version_id}\")\n\n    try:\n        agent = await prisma.models.StoreAgent.prisma().find_first(\n            where={\"listing_version_id\": store_listing_version_id}\n        )\n\n        if not agent:","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/db.py#L370-L406","documentation":"DatabaseError raised by get_available_graph when the StoreListingVersion/AgentGraph query itself fails or GraphModel(WithoutNodes).from_db cannot build the model (e.g. malformed graph JSON in the DB). The NotFoundError case is deliberately wrapped too — unlike sibling functions it has no 'except NotFoundError: raise', so not-found surfaces as this DatabaseError upstream.","triggerScenarios":"Fetching an available graph while the DB errors, the include of AgentGraph with AGENT_GRAPH_INCLUDE fails on inconsistent relations, or graph node/link JSON stored in the DB doesn't match the model (schema drift between graph versions).","commonSituations":"Graphs created by an older backend version with fields the current from_db rejects; interrupted graph saves leaving partial JSON; Prisma client/schema mismatch; DB connectivity issues.","solutions":["Check logs for 'Error getting agent' with the chained cause.","If it's graph JSON/model drift, re-save the affected graph with the current backend or run the graph-migration fix for stored JSON.","Regenerate the Prisma client after schema changes.","On persistent failure, verify the specific listing version's graph rows directly in the DB for corruption."],"exampleFix":"# before — not-found is swallowed into DatabaseError\nexcept Exception as e:\n    raise DatabaseError(\"Failed to fetch agent\") from e\n# after — preserve the 404 semantics\nexcept NotFoundError:\n    raise\nexcept Exception as e:\n    raise DatabaseError(\"Failed to fetch agent\") from e","handlingStrategy":"try-catch","validationCode":"// Nothing user-side can prevent DB/model failures; validate the id shape at least\nif (!/^[a-z0-9]{20,}$/.test(versionId)) throw new RangeError('bad version id');","typeGuard":"function isDatabaseError(e: unknown): e is DatabaseError {\n  return e instanceof Error && e.message === 'Failed to fetch agent';\n}","tryCatchPattern":"try { return await getAvailableGraph(versionId); }\ncatch (e) {\n  // note: not-found is ALSO wrapped here — check the cause chain\n  if (e instanceof DatabaseError && e.__cause__ instanceof NotFoundError) return null;\n  throw e;\n}","preventionTips":["Because NotFoundError is wrapped in this function, always inspect __cause__ to distinguish 404 from real DB errors (or patch the function to re-raise NotFoundError).","Re-save graphs with the current backend after graph-schema migrations.","Keep prisma client generated as part of the deploy pipeline."],"tags":["database","prisma","store","graphs","error-mapping"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}