{"record":{"id":"677598ced27c097a","repo":"Significant-Gravitas/AutoGPT","slug":"workspace-does-not-belong-to-this-organization","errorCode":null,"errorMessage":"Workspace does not belong to this organization","messagePattern":"Workspace does not belong to this organization","errorType":"http","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/orgs/team_db.py","lineNumber":103,"sourceCode":"\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    )\n    if org_member is None:\n        raise ValueError(f\"User {user_id} is not a member of the organization\")\n\n    # Check not already a member\n    existing = await prisma.teammember.find_unique(\n        where={\"teamId_userId\": {\"teamId\": ws_id, \"userId\": user_id}}\n    )\n    if existing:\n        return TeamResponse.from_db(ws)\n\n    await prisma.teammember.create(","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/orgs/team_db.py#L85-L121","documentation":"Raised by team_db.join_team when the found workspace's orgId does not equal the org_id passed in. It prevents joining a workspace through the wrong organization's URL scope. Plain ValueError from the DB layer.","triggerScenarios":"POST /api/orgs/{org_id}/workspaces/{ws_id}/join where ws_id belongs to a different org than org_id in the path. Typically a URL assembled from mixed sources (org id from one context, workspace id from another), or after a workspace was moved/recreated under another org.","commonSituations":"Deep links or bookmarks built from a previous org context; multi-org clients where the active org switch did not refresh workspace references; test fixtures that pair unrelated org and workspace ids.","solutions":["Always derive ws_id and org_id from the same TeamResponse object (its orgId field) when constructing the join URL","Re-fetch the workspace via GET /api/orgs/{org_id}/workspaces and use the returned id","In the client, catch this and reset the user's active-org/workspace selection so links are rebuilt consistently","Audit generated links/emails to embed both ids from one source"],"exampleFix":"// before\nconst url = `/api/orgs/${activeOrgId}/workspaces/${cachedWsId}/join`;\n// after\nconst ws = await getWorkspace(activeOrgId, cachedWsId); // 404/does-not-belong if stale\nconst url = `/api/orgs/${ws.orgId}/workspaces/${ws.id}/join`;","handlingStrategy":"validation","validationCode":"const ws = await getWorkspace(orgId, wsId).catch(() => null);\nif (!ws || ws.orgId !== orgId) throw new Error('Workspace does not belong to this org');","typeGuard":"function workspaceInOrg(ws: TeamResponse, orgId: string): boolean {\n  return ws.orgId === orgId;\n}","tryCatchPattern":"try {\n  await joinTeam(orgId, wsId);\n} catch (e) {\n  if (e.message.includes('does not belong to this organization')) {\n    // reset active org/workspace selection and rebuild the URL\n  } else throw e;\n}","preventionTips":["Always construct org+workspace URL pairs from a single TeamResponse","Re-validate on org switch"],"tags":["workspaces","orgs","join","valueerror"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}