{"record":{"id":"e89943579a66706e","repo":"Significant-Gravitas/AutoGPT","slug":"failed-to-create-store-review","errorCode":null,"errorMessage":"Failed to create store review","messagePattern":"Failed to create store review","errorType":"exception","errorClass":"DatabaseError","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/store/db.py","lineNumber":1185,"sourceCode":"        )\n        review = await prisma.models.StoreListingReview.prisma().upsert(\n            where={\n                \"storeListingVersionId_reviewByUserId\": {\n                    \"storeListingVersionId\": store_listing_version_id,\n                    \"reviewByUserId\": user_id,\n                }\n            },\n            data=data,\n        )\n\n        return store_model.StoreReview(\n            score=review.score,\n            comments=review.comments,\n        )\n\n    except prisma.errors.PrismaError as e:\n        logger.error(f\"Database error creating store review: {e}\")\n        raise DatabaseError(\"Failed to create store review\") from e\n\n\nasync def get_user_profile(\n    user_id: str,\n) -> store_model.ProfileDetails | None:\n    logger.debug(f\"Getting user profile for {user_id}\")\n\n    try:\n        profile = await prisma.models.Profile.prisma().find_first(\n            where={\"userId\": user_id}\n        )\n\n        if not profile:\n            return None\n        return store_model.ProfileDetails.from_db(profile)\n    except Exception as e:\n        logger.error(f\"Error getting user profile: {e}\")\n        raise DatabaseError(\"Failed to get user profile\") from e","sourceCodeStart":1167,"sourceCodeEnd":1203,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/db.py#L1167-L1203","documentation":"Generic wrapper around create_store_review: any prisma.errors.PrismaError during the review upsert becomes this DatabaseError. The upsert targets a StoreListingReview keyed by user + listing version; the most common underlying cause is a P2003 foreign-key violation because store_listing_version_id does not exist (reviewing a version that was deleted or never published), or a not-null/constraint failure on score.","triggerScenarios":"POST a review for a store_listing_version_id from a stale page after the listing was updated to a new version and the old version row removed; review submitted from a different environment (staging ID against prod); score outside the column's constraint.","commonSituations":"Store page open in a tab while the creator publishes a new version; deep links to old listing versions; browser back-forward to a cached review form.","solutions":["Verify the listing version exists: GET the store agent details and resubmit with its current store_listing_version_id.","Check logs for the PrismaError code (P2003 = FK, P2002 = duplicate) to confirm.","For robustness, offer the review against the listing's current version rather than a pinned one."],"exampleFix":"// before\nawait api.createReview(oldVersionId, { score: 5 });\n// after\nconst details = await api.getStoreAgent(slug);\nawait api.createReview(details.store_listing_version_id, { score: 5 });","handlingStrategy":"validation","validationCode":"const details = await api.getStoreAgent(slug);\nconst versionId = details.store_listing_version_id; // always the live version\nawait api.createReview(versionId, { score, comments });","typeGuard":null,"tryCatchPattern":"from backend.util.exceptions import DatabaseError\n\ntry:\n    await store_db.create_store_review(user_id, version_id, score, comments)\nexcept DatabaseError as e:\n    if getattr(e.__cause__, 'code', None) == 'P2003':\n        ui.show('This listing version is no longer available — reload the page');\n    else:\n        raise","preventionTips":["Resolve the current store_listing_version_id from the listing details at review time.","Treat deep links to old listing versions as fresh navigations that refetch state.","Check the chained PrismaError code before deciding to retry vs reload."],"tags":["database","prisma","review","store","stale-reference"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}