Significant-Gravitas/AutoGPT · error · ValueError

Cannot change the default workspace's join policy

Error message

Cannot change the default workspace's join policy

What it means

Raised by team_db.update_team when a PATCH workspace request includes a 'joinPolicy' field and the target workspace has isDefault=true. Every org has one default workspace that all org members must be able to join, so its join policy is immutable. It is a plain ValueError raised at the DB layer; over HTTP the route (update_team in team_routes.py) surfaces it as a 400/500 depending on the app's exception mapping.

Source

Thrown at autogpt_platform/backend/backend/api/features/orgs/team_db.py:80

    ws = await prisma.team.find_unique(where={"id": ws_id})
    if ws is None:
        raise NotFoundError(f"Workspace {ws_id} not found")
    if expected_org_id and ws.orgId != expected_org_id:
        raise NotFoundError(f"Workspace {ws_id} not found in org {expected_org_id}")
    return TeamResponse.from_db(ws)


async def update_team(ws_id: str, data: dict) -> TeamResponse:
    """Update workspace fields. Guards the default workspace join policy."""
    update_data = {k: v for k, v in data.items() if v is not None}
    if not update_data:
        return await get_team(ws_id)

    # Guard: default workspace joinPolicy cannot be changed
    if "joinPolicy" in update_data:
        ws = await prisma.team.find_unique(where={"id": ws_id})
        if ws and ws.isDefault:
            raise ValueError("Cannot change the default workspace's join policy")

    await prisma.team.update(where={"id": ws_id}, data=update_data)
    return await get_team(ws_id)


async def delete_team(ws_id: str) -> None:
    """Delete a workspace. Cannot delete the default workspace."""
    ws = await prisma.team.find_unique(where={"id": ws_id})
    if ws is None:
        raise NotFoundError(f"Workspace {ws_id} not found")
    if ws.isDefault:
        raise ValueError("Cannot delete the default workspace")

    await prisma.team.delete(where={"id": ws_id})


async def join_team(ws_id: str, user_id: str, org_id: str) -> TeamResponse:
    """Self-join an OPEN workspace. User must be an org member."""

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Send only the fields you intend to change — omit join_policy entirely when PATCHing the default workspace
  2. If the UI must show the control, disable it for workspaces where isDefault is true (TeamResponse exposes it)
  3. Switch the join policy on a non-default workspace, or create a new workspace with the desired policy instead
  4. If you genuinely need the default workspace open/closed org-wide, change the org's membership rules, not the workspace joinPolicy

Example fix

// before
await sdk.patchWorkspace(orgId, wsId, {
  name: newName,
  joinPolicy: currentJoinPolicy, // always sent -> 400 on default ws
});
// after
await sdk.patchWorkspace(orgId, wsId, { name: newName });
Defensive patterns

Strategy: validation

Validate before calling

const ws = await getWorkspace(orgId, wsId);
if (ws.isDefault && 'joinPolicy' in patch) {
  throw new Error('Default workspace join policy is immutable');
}

Type guard

function isDefaultWorkspace(ws: TeamResponse): boolean {
  return ws.isDefault === true;
}

Try / catch

try {
  await patchWorkspace(orgId, wsId, patch);
} catch (e) {
  if (e instanceof Error && e.message.includes("default workspace's join policy")) {
    // strip joinPolicy and retry with editable fields only
    const { joinPolicy, ...rest } = patch;
    await patchWorkspace(orgId, wsId, rest);
  } else throw e;
}

Prevention

When it happens

Trigger: PATCH /api/orgs/{org_id}/workspaces/{ws_id} with a body containing join_policy (e.g. {"join_policy": "PRIVATE"}) where ws_id is the org's default workspace. Only fires when joinPolicy is a non-None key in the update dict; omitting the field or sending null skips the guard.

Common situations: Frontend settings form that always submits the full workspace object (including joinPolicy) even when the user only edited name/description; admin tooling that copies a non-default workspace's payload onto the default workspace; tests that reuse one fixture payload for all workspaces.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/b20e1714c13def8f. Report an issue: GitHub.