{"record":{"id":"39f09983d01d4d09","repo":"Significant-Gravitas/AutoGPT","slug":"cannot-delete-the-default-workspace","errorCode":null,"errorMessage":"Cannot delete the default workspace","messagePattern":"Cannot delete the default workspace","errorType":"http","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/orgs/team_db.py","lineNumber":92,"sourceCode":"        return await get_team(ws_id)\n\n    # Guard: default workspace joinPolicy cannot be changed\n    if \"joinPolicy\" in update_data:\n        ws = await prisma.team.find_unique(where={\"id\": ws_id})\n        if ws and ws.isDefault:\n            raise ValueError(\"Cannot change the default workspace's join policy\")\n\n    await prisma.team.update(where={\"id\": ws_id}, data=update_data)\n    return await get_team(ws_id)\n\n\nasync def delete_team(ws_id: str) -> None:\n    \"\"\"Delete a workspace. Cannot delete the default workspace.\"\"\"\n    ws = await prisma.team.find_unique(where={\"id\": ws_id})\n    if ws is None:\n        raise NotFoundError(f\"Workspace {ws_id} not found\")\n    if ws.isDefault:\n        raise ValueError(\"Cannot delete the default workspace\")\n\n    await prisma.team.delete(where={\"id\": ws_id})\n\n\nasync def join_team(ws_id: str, user_id: str, org_id: str) -> TeamResponse:\n    \"\"\"Self-join an OPEN workspace. User must be an org member.\"\"\"\n    ws = await prisma.team.find_unique(where={\"id\": ws_id})\n    if ws is None:\n        raise NotFoundError(f\"Workspace {ws_id} not found\")\n    if ws.orgId != org_id:\n        raise ValueError(\"Workspace does not belong to this organization\")\n    if ws.joinPolicy != \"OPEN\":\n        raise ValueError(\"Cannot self-join a PRIVATE workspace. Request an invite.\")\n\n    # Verify user is actually an org member\n    org_member = await prisma.orgmember.find_unique(\n        where={\"orgId_userId\": {\"orgId\": org_id, \"userId\": user_id}}\n    )","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/orgs/team_db.py#L74-L110","documentation":"Raised by team_db.delete_team when the target workspace has isDefault=true. Each org has exactly one default workspace that anchors membership and cannot be removed; deleting it would orphan the org's members. Plain ValueError from the DB layer; the DELETE route returns it as a 400-class failure.","triggerScenarios":"DELETE /api/orgs/{org_id}/workspaces/{ws_id} where ws_id is the default workspace (created automatically with the org, isDefault=true). Commonly triggered by 'delete' buttons in a workspace list UI that do not special-case the default row.","commonSituations":"UI iterates all workspaces and offers delete on each, including the default one; scripted cleanup that deletes every workspace in an org; user confusion between the personal/default workspace and user-created ones.","solutions":["Hide or disable the delete action for workspaces where isDefault is true in the response payload","To remove the workspace entirely, delete the organization instead (the default workspace dies with it)","Create replacement workspaces first, migrate members, then delete the org if you are tearing down","If testing, use a workspace created via create_team — those are never the default"],"exampleFix":"// before\n{workspaces.map(ws => <DeleteButton onClick={() => del(ws.id)} />)}\n// after\n{workspaces.map(ws => (\n  ws.isDefault ? <Tooltip>Default workspace cannot be deleted</Tooltip> : <DeleteButton onClick={() => del(ws.id)} />\n))}","handlingStrategy":"validation","validationCode":"const ws = await getWorkspace(orgId, wsId);\nif (ws.isDefault) {\n  throw new Error('The default workspace cannot be deleted; delete the organization instead.');\n}","typeGuard":"function isDeletableWorkspace(ws: TeamResponse): boolean {\n  return ws.isDefault !== true;\n}","tryCatchPattern":"try {\n  await deleteWorkspace(orgId, wsId);\n} catch (e) {\n  if (e.message.includes('Cannot delete the default workspace')) {\n    showToast('Default workspaces cannot be deleted');\n  } else throw e;\n}","preventionTips":["Disable delete actions for isDefault rows in list UIs","Default to org-level teardown when the default workspace must go"],"tags":["workspaces","orgs","valueerror","guard"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}