langflow-ai/langflow · error · HTTPException

user_id not found

Error message

user_id not found

What it means

Raised by POST /api/v1/authz/role-assignments when the user_id in the RoleAssignmentCreate payload does not match any row in the user table. The route does session.get(User, payload.user_id) first and returns HTTP 404 before looking at the role.

Source

Thrown at src/backend/base/langflow/api/v1/authz_role_assignments.py:96

        stmt = stmt.where(AuthzRoleAssignment.domain_id == domain_id)
    stmt = stmt.order_by(AuthzRoleAssignment.assigned_at.desc(), AuthzRoleAssignment.id).offset(offset).limit(limit)
    rows = (await session.exec(stmt)).all()
    return [RoleAssignmentRead.model_validate(row) for row in rows]


@router.post("", response_model=RoleAssignmentRead, status_code=status.HTTP_201_CREATED)
@router.post("/", response_model=RoleAssignmentRead, status_code=status.HTTP_201_CREATED)
async def create_assignment(
    payload: RoleAssignmentCreate,
    current_user: CurrentActiveUser,
    session: DbSession,
) -> RoleAssignmentRead:
    """Assign a role to a user. Superuser-only."""
    _require_superuser(current_user)

    user = await session.get(User, payload.user_id)
    if user is None:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="user_id not found")
    role = await session.get(AuthzRole, payload.role_id)
    if role is None:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="role_id not found")

    assignment = AuthzRoleAssignment(
        user_id=payload.user_id,
        role_id=payload.role_id,
        domain_type=payload.domain_type,
        domain_id=payload.domain_id,
        assigned_at=datetime.now(timezone.utc),
        assigned_by=current_user.id,
    )
    session.add(assignment)
    try:
        await session.commit()
    except IntegrityError as exc:
        await session.rollback()
        raise HTTPException(

View on GitHub (pinned to 976ec789d2)

Solutions

  1. Re-fetch the current user list (GET /api/v1/users) and use a live id
  2. If scripting, look the user up by username first and derive the id at runtime
  3. Confirm you are pointed at the correct environment/database
  4. Handle 404 non-retryable: surface 'user does not exist' rather than retrying

Example fix

// before
await api.post('/authz/role-assignments', { user_id: ' stale-uuid', role_id });

// after
const users = await api.get('/api/v1/users');
const u = users.find(x => x.username === 'alice');
if (!u) throw new Error('user not found');
await api.post('/authz/role-assignments', { user_id: u.id, role_id });
Defensive patterns

Strategy: validation

Validate before calling

const users = await api.get('/api/v1/users');
const target = users.find(u => u.id === payload.user_id);
if (!target) throw new Error('user does not exist');

Type guard

const isUuid = (v: string): boolean =>
  /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v);

Try / catch

catch (e) { if (e.status === 404) showFormError('Selected user no longer exists'); }

Prevention

When it happens

Trigger: POST with a user_id that was deleted, a typo'd/malformed UUID, or the id of a user from a different environment (e.g. a dev database UUID pasted into a prod script).

Common situations: Stale user lists in an admin UI after users were removed, copying fixture UUIDs between environments, or orchestrating role assignments from config files that drift from the actual user table.

Related errors


AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14). Data as JSON: /api/errors/1f596ec89ab86606. Report an issue: GitHub.