{"record":{"id":"ae62e4e9cb467ae3","repo":"Significant-Gravitas/AutoGPT","slug":"unique-constraint-violated-not-slug-error-str","errorCode":null,"errorMessage":"Unique constraint violated (not slug): {error_str}","messagePattern":"Unique constraint violated \\(not slug\\): (.+?)","errorType":"exception","errorClass":"DatabaseError","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/store/db.py","lineNumber":1016,"sourceCode":"            )\n\n        if not new_submission:\n            raise DatabaseError(\"Failed to create store listing version\")\n\n        logger.debug(f\"Created store listing for agent {graph_id}\")\n        return store_model.StoreSubmission.from_listing_version(new_submission)\n    except prisma.errors.UniqueViolationError as exc:\n        # Attempt to check if the error was due to the slug field being unique\n        error_str = str(exc)\n        if \"slug\" in error_str.lower():\n            logger.debug(f\"Slug '{slug}' is already in use by graph #{graph_id}\")\n            raise store_exceptions.SlugAlreadyInUseError(\n                f\"The slug '{slug}' is already in use by another one of your agents. \"\n                \"Please choose a different slug.\"\n            ) from exc\n        else:\n            # Reraise as a generic database error for other unique violations\n            raise DatabaseError(\n                f\"Unique constraint violated (not slug): {error_str}\"\n            ) from exc\n    except (\n        NotFoundError,\n        store_exceptions.ListingExistsError,\n    ):\n        raise\n    except prisma.errors.PrismaError as e:\n        logger.error(f\"Database error creating store submission: {e}\")\n        raise DatabaseError(\"Failed to create store submission\") from e\n\n\nasync def edit_store_submission(\n    user_id: str,\n    store_listing_version_id: str,\n    name: str,\n    video_url: str | None = None,\n    agent_output_demo_url: str | None = None,","sourceCodeStart":998,"sourceCodeEnd":1034,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/db.py#L998-L1034","documentation":"DatabaseError raised when the insert hits a UniqueViolationError whose message does not contain 'slug'. The store schema has several unique constraints — notably StoreListing.agentGraphId (one listing per agent) and StoreListingVersion composite keys — so this usually means a listing already exists for that agent graph, or a version-key collision. The raw Postgres error text is embedded in the message, which tells you the exact constraint name.","triggerScenarios":"POST /store/submissions for an agent that already has a StoreListing while the code path attempts create (instead of the existing-listing update path); concurrent double submission both passing the exists-check and racing the insert; retrying a request whose first attempt actually committed.","commonSituations":"Publishing the same agent twice quickly; a network timeout on the first POST that actually succeeded, followed by a client retry; ListingExistsError check bypassed due to stale state.","solutions":["Read the constraint name in the message (e.g. 'StoreListing_agentGraphId_key') to identify the collision.","If the listing already exists, use the edit/submission-update flow (edit_store_submission) instead of creating a new listing.","Guard the UI against double submits; on retry-after-timeout, first GET the agent's submissions to see if it already exists.","For version collisions, recompute the next version number from the latest listing version instead of a client-supplied value."],"exampleFix":"// before\nawait api.createSubmission(payload); // retried blindly after timeout\n// after\nconst existing = await api.getMySubmissions().then(s => s.find(x => x.agent_id === payload.graph_id));\nif (existing) await api.editSubmission(existing.store_listing_version_id, payload);\nelse await api.createSubmission(payload);","handlingStrategy":"try-catch","validationCode":"const existing = await api.getMySubmissions()\n  .then(list => list.find(s => s.agent_id === payload.graph_id));\nif (existing) {\n  await api.editSubmission(existing.store_listing_version_id, payload);\n} else {\n  await api.createSubmission(payload);\n}","typeGuard":null,"tryCatchPattern":"from backend.api.features.store import store_exceptions\nfrom backend.util.exceptions import DatabaseError\n\ntry:\n    await store_db.create_store_submission(...)\nexcept store_exceptions.SlugAlreadyInUseError:\n    ui.show('Choose a different slug');\nexcept DatabaseError as e:\n    if 'Unique constraint violated' in str(e):\n        ui.refreshSubmissions()  # listing likely already exists; switch to edit flow\n    else:\n        raise","preventionTips":["After a timed-out submit, GET the submissions for that graph before retrying the POST.","Read the constraint name embedded in the error to tell slug vs agentGraphId collisions apart.","Prefer the edit flow whenever a listing already exists for the agent."],"tags":["database","unique-constraint","submission","store","race-condition"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}