{"record":{"id":"cf5bb68649aeee5c","repo":"Significant-Gravitas/AutoGPT","slug":"user-user-id-is-not-a-member-of-the-organization","errorCode":null,"errorMessage":"User {user_id} is not a member of the organization","messagePattern":"User (.+?) is not a member of the organization","errorType":"http","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/orgs/team_db.py","lineNumber":112,"sourceCode":"    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(\n        data={\n            \"teamId\": ws_id,\n            \"userId\": user_id,\n            \"status\": \"ACTIVE\",\n        }\n    )\n    return TeamResponse.from_db(ws)\n\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/orgs/team_db.py#L94-L130","documentation":"Raised by team_db.join_team when no OrgMember row exists for (org_id, user_id). Self-join requires org membership first — workspace membership is a subset of org membership in this data model. Plain ValueError from the DB layer.","triggerScenarios":"POST /api/orgs/{org_id}/workspaces/{ws_id}/join where the authenticated user has not been added to the organization (no row in the OrgMember table for that pair). The route's ctx.org_id check may already block cross-org calls with 403, so this is mostly hit via direct DB-layer use, org membership revocation races, or the org_id path belonging to a workspace whose org the user never joined.","commonSituations":"User was removed from the org but still has an old session/UI state pointing at its workspaces; invitation to the org accepted but not yet propagated; tests calling team_db.join_team directly without creating the OrgMember fixture row.","solutions":["Have the user accept an org invitation or be added as an org member first (org member endpoints), then retry the workspace join","Verify membership with the org-members API (GET org members) before exposing the join action","If membership was recently revoked, refresh the user's org list and redirect them out of the removed org's UI","In tests, create the OrgMember row in the fixture before calling join_team"],"exampleFix":"# before (test fixture)\nawait team_db.join_team(ws_id, user_id, org_id)  # raises: not an org member\n# after\nawait prisma.orgmember.create(data={\"orgId\": org_id, \"userId\": user_id, \"role\": \"MEMBER\"})\nawait team_db.join_team(ws_id, user_id, org_id)","handlingStrategy":"validation","validationCode":"const isMember = await isOrgMember(orgId, userId); // org members API\nif (!isMember) throw new Error('Join the organization first');","typeGuard":null,"tryCatchPattern":"try {\n  await joinTeam(orgId, wsId);\n} catch (e) {\n  if (e.message.includes('not a member of the organization')) {\n    // route user to org invitation flow\n  } else throw e;\n}","preventionTips":["Ensure org membership before exposing workspace join","Create OrgMember fixture rows in tests before join_team"],"tags":["workspaces","orgs","join","membership","valueerror"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}