{"record":{"id":"d010ec6ebcceb01b","repo":"Significant-Gravitas/AutoGPT","slug":"workspace-ws-id-not-found","errorCode":null,"errorMessage":"Workspace {ws_id} not found","messagePattern":"Workspace (.+?) not found","errorType":"http","errorClass":"NotFoundError","httpStatus":404,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/orgs/team_db.py","lineNumber":64,"sourceCode":"    workspaces = await prisma.team.find_many(\n        where={\n            \"orgId\": org_id,\n            \"archivedAt\": None,\n            \"OR\": [\n                {\"joinPolicy\": \"OPEN\"},\n                {\"Members\": {\"some\": {\"userId\": user_id, \"status\": \"ACTIVE\"}}},\n            ],\n        },\n        order={\"createdAt\": \"asc\"},\n    )\n    return [TeamResponse.from_db(ws) for ws in workspaces]\n\n\nasync def get_team(ws_id: str, expected_org_id: str | None = None) -> TeamResponse:\n    \"\"\"Get workspace details. Validates org ownership if expected_org_id is given.\"\"\"\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 expected_org_id and ws.orgId != expected_org_id:\n        raise NotFoundError(f\"Workspace {ws_id} not found in org {expected_org_id}\")\n    return TeamResponse.from_db(ws)\n\n\nasync def update_team(ws_id: str, data: dict) -> TeamResponse:\n    \"\"\"Update workspace fields. Guards the default workspace join policy.\"\"\"\n    update_data = {k: v for k, v in data.items() if v is not None}\n    if not update_data:\n        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)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/orgs/team_db.py#L46-L82","documentation":"Raised by get_team() in team_db.py when prisma.team.find_unique for ws_id returns null — no Team (workspace) row exists with that id. Raised as NotFoundError (HTTP 404). Callers pass expected_org_id to additionally validate org ownership; this variant is the plain miss.","triggerScenarios":"GET/PATCH team endpoints or any get_team(ws_id) call with a deleted workspace id, a typo'd id, or an id from another environment.","commonSituations":"Frontend caches workspace list after a workspace was deleted; URL parameters from old sessions; test fixtures with hardcoded ids drifting after DB resets.","solutions":["Verify the id against a fresh team list (list_user_teams) before use.","Check prisma.team.find_unique(where={'id': ws_id}) directly if the workspace is expected to exist.","On 404, remove the workspace from local state and redirect to the workspace picker."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const teams = await api.get('/api/teams').then(r => r.data);\nconst exists = teams.some(t => t.id === wsId);\nif (!exists) redirectToTeamPicker();","typeGuard":null,"tryCatchPattern":"try {\n  return await get_team(ws_id);\n} catch (NotFoundError) {\n  raise HTTPException(404, 'Workspace no longer exists')\n}","preventionTips":["Use ids only from a freshly fetched team list","Purge cached workspace ids after deletions","Redirect to the picker on 404 instead of error loops"],"tags":["teams","workspaces","not-found","http-404"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}