{"record":{"id":"c109d5dfe9364db7","repo":"Significant-Gravitas/AutoGPT","slug":"storelisting-listing-id-has-no-creatorprofile","errorCode":null,"errorMessage":"StoreListing {listing.id} has no CreatorProfile — FK violated","messagePattern":"StoreListing (.+?) has no CreatorProfile — FK violated","errorType":"exception","errorClass":"DatabaseError","httpStatus":500,"severity":"critical","filePath":"autogpt_platform/backend/backend/api/features/store/db.py","lineNumber":441,"sourceCode":"    StoreAgent view. Queries StoreListingVersion directly so pending\n    submissions are visible.\"\"\"\n    slv = await prisma.models.StoreListingVersion.prisma().find_unique(\n        where={\"id\": store_listing_version_id},\n        include={\n            \"StoreListing\": {\"include\": {\"CreatorProfile\": True}},\n        },\n    )\n    if not slv or not slv.StoreListing:\n        raise NotFoundError(\n            f\"Store listing version {store_listing_version_id} not found\"\n        )\n\n    listing = slv.StoreListing\n    # CreatorProfile is a required FK relation — should always exist.\n    # If it's None, the DB is in a bad state.\n    profile = listing.CreatorProfile\n    if not profile:\n        raise DatabaseError(\n            f\"StoreListing {listing.id} has no CreatorProfile — FK violated\"\n        )\n\n    return store_model.StoreAgentDetails(\n        store_listing_version_id=slv.id,\n        slug=listing.slug,\n        agent_name=slv.name,\n        agent_video=slv.videoUrl or \"\",\n        agent_output_demo=slv.agentOutputDemoUrl or \"\",\n        agent_image=slv.imageUrls,\n        creator=profile.username,\n        creator_avatar=profile.avatarUrl or \"\",\n        sub_heading=slv.subHeading,\n        description=slv.description,\n        instructions=slv.instructions,\n        categories=slv.categories,\n        runs=0,\n        rating=0.0,","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/db.py#L423-L459","documentation":"Raised by get_store_agent_details when a StoreListing row's CreatorProfile relation is None. The schema declares CreatorProfile as a required FK on StoreListing, so a None relation means the database is in a corrupt or inconsistent state (e.g. the creator row was deleted without cascading, or data was imported/migrated without the relation). It is wrapped as DatabaseError, which the API layer surfaces as a 500-class failure. This is not caused by bad user input; it signals a data-integrity break between StoreListing and Creator/Profile.","triggerScenarios":"Calling the store agent details endpoint (GET /store/search/agents or the details route that resolves a store_listing_version_id) for a listing whose CreatorProfile relation resolves to None. Typically happens after a Creator/Profile row was manually deleted via SQL, after a partial prisma migrate, or after seeding StoreListing rows without their creator relation.","commonSituations":"Manual DB cleanup scripts that delete Profile or Creator rows referenced by StoreListing; FK constraints disabled or ON DELETE behavior changed in a migration; test fixtures that create StoreListing without CreatorProfile; env mismatch where the app points at a stale/dirty database snapshot.","solutions":["Run an integrity query: SELECT id FROM \"StoreListing\" sl LEFT JOIN \"Profile\" p ON p.\"userId\" = sl.\"submissionAgentId\" WHERE p.\"userId\" IS NULL (adjust to the actual FK column) to find orphan listings.","Restore the missing Creator/Profile row, or delete/recreate the orphaned StoreListing and its versions.","Verify the Prisma schema's relation and the underlying SQL FK constraint (ON DELETE RESTRICT or CASCADE) so future creator deletions cannot orphan listings.","If this fires across many listings after a migration, roll back the migration and re-run it with the correct relation data."],"exampleFix":"// before: orphan listing left in DB after creator deletion\nDELETE FROM \"Profile\" WHERE \"userId\" = 'usr_123'; -- leaves StoreListing.CreatorProfile dangling\n// after: remove dependent listings atomically, or block the delete\nBEGIN;\nDELETE FROM \"StoreListingVersion\" WHERE \"storeListingId\" IN (SELECT id FROM \"StoreListing\" WHERE \"submissionAgentId\" = 'usr_123');\nDELETE FROM \"StoreListing\" WHERE \"submissionAgentId\" = 'usr_123';\nDELETE FROM \"Profile\" WHERE \"userId\" = 'usr_123';\nCOMMIT;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from backend.util.exceptions import DatabaseError\n\ntry:\n    details = await store_db.get_store_agent_details(version_id)\nexcept DatabaseError as e:\n    if 'no CreatorProfile' in str(e):\n        logger.critical('Data integrity: orphan StoreListing %s', version_id)\n        raise StoreIntegrityAlert(version_id) from e\n    raise","preventionTips":["Never delete Creator/Profile rows with raw SQL; go through code that cascades StoreListing and its versions.","Add a CI integrity check that flags StoreListing rows whose creator relation is NULL.","Seed test fixtures through the real submission flow so listings always have creators."],"tags":["database","prisma","foreign-key","data-integrity","store"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}