{"record":{"id":"a7eea55b226a803f","repo":"Significant-Gravitas/AutoGPT","slug":"slug-slug-is-already-in-use","errorCode":null,"errorMessage":"Slug '{slug}' is already in use","messagePattern":"Slug '(.+?)' is already in use","errorType":"http","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/orgs/db.py","lineNumber":230,"sourceCode":"# ---------------------------------------------------------------------------\n# Org CRUD\n# ---------------------------------------------------------------------------\n\n\nasync def create_org(\n    name: str,\n    slug: str,\n    user_id: str,\n    description: str | None = None,\n) -> OrgResponse:\n    \"\"\"Create a team organization and make the user the owner.\n\n    Raises:\n        ValueError: If the slug is already taken by another org or alias.\n    \"\"\"\n    existing_org = await prisma.organization.find_unique(where={\"slug\": slug})\n    if existing_org:\n        raise ValueError(f\"Slug '{slug}' is already in use\")\n    existing_alias = await prisma.organizationalias.find_unique(\n        where={\"aliasSlug\": slug}\n    )\n    if existing_alias:\n        raise ValueError(f\"Slug '{slug}' is already in use as an alias\")\n\n    # One transaction: a failure partway must not leave an org without its\n    # default workspace, owner membership, profile, seat, or balance row.\n    async with transaction() as tx:\n        org = await tx.organization.create(\n            data={\n                \"name\": name,\n                \"slug\": slug,\n                \"description\": description,\n                \"isPersonal\": False,\n                \"bootstrapUserId\": user_id,\n                \"settings\": \"{}\",\n            }","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/orgs/db.py#L212-L248","documentation":"ValueError raised by create_org when the requested slug already exists as an organization slug. The API layer typically maps this to a 400/409. Slug uniqueness is enforced with a lookup before creation, so the transaction never starts in this case.","triggerScenarios":"POST create organization with a slug identical to an existing org's slug (e.g. 'acme-team' when another org already uses it).","commonSituations":"Auto-generated slugs colliding for common company names; retrying a create that actually succeeded on the first attempt; two users claiming the same slug simultaneously.","solutions":["Choose a different, more specific slug (add a suffix like -hq or -inc)","If the slug belongs to an org you own, reuse that org instead of creating a new one","Handle the error in the client by prompting the user for a new slug"],"exampleFix":"# before\norg = await create_org(name=\"Acme\", slug=\"acme\", user_id=uid)\n# after\ntry:\n    org = await create_org(name=\"Acme\", slug=\"acme\", user_id=uid)\nexcept ValueError as e:\n    if \"already in use\" in str(e):\n        org = await create_org(name=\"Acme\", slug=\"acme-2\", user_id=uid)","handlingStrategy":"try-catch","validationCode":"existing = await prisma.organization.find_unique(where={\"slug\": slug})\nif existing:\n    raise ValueError(\"slug taken — pick another before create\")","typeGuard":null,"tryCatchPattern":"try:\n    org = await create_org(name=name, slug=slug, user_id=uid)\nexcept ValueError as e:\n    if \"already in use\" in str(e):\n        slug = f\"{slug}-{suffix()}\"\n        org = await create_org(name=name, slug=slug, user_id=uid)\n    else:\n        raise","preventionTips":["Pre-check slug availability in the UI as the user types","Auto-suffix on collision for machine-created orgs","Never assume a failed create left no state — verify before retrying"],"tags":["orgs","validation","conflict","slug"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}