langflow-ai/langflow · error · HTTPException
role_id not found
Error message
role_id not found
What it means
Raised by POST /api/v1/authz/role-assignments when payload.role_id does not reference an existing AuthzRole row. The user lookup succeeded, but session.get(AuthzRole, payload.role_id) returned None, giving HTTP 404 'role_id not found'.
Source
Thrown at src/backend/base/langflow/api/v1/authz_role_assignments.py:99
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(
status_code=status.HTTP_409_CONFLICT,
detail="Assignment already exists for this user/role/domain",
) from excView on GitHub (pinned to 976ec789d2)
Solutions
- List roles via GET /api/v1/authz/roles and select by name instead of a stored UUID
- In scripts, resolve role ids dynamically: find role by name, then assign
- Treat as non-retryable: fix the payload rather than retrying
Example fix
// before
await api.post('/authz/role-assignments', { user_id, role_id: '68f1...' });
// after
const roles = await api.get('/api/v1/authz/roles');
const dev = roles.find(r => r.name === 'developer');
await api.post('/authz/role-assignments', { user_id, role_id: dev.id }); Defensive patterns
Strategy: validation
Validate before calling
const roles = await api.get('/api/v1/authz/roles');
if (!roles.some(r => r.id === payload.role_id)) throw new Error('role does not exist'); Try / catch
catch (e) { if (e.status === 404) refreshRolesAndRepick(); } Prevention
- Look roles up by name at runtime rather than persisting UUIDs
- Create roles before referencing them as parents or assignment targets
- Refresh role lists in admin pickers on window focus
When it happens
Trigger: POST an assignment referencing a custom role that was deleted, a system role id from a different Langflow install, or a role UUID that was regenerated when the authz foundations migration re-seeded roles.
Common situations: Hard-coded role UUIDs in provisioning scripts that break when roles are recreated, mixing ids between environments, or referencing a role deleted by another admin between the UI load and the submit.
Related errors
- user_id not found
- Assignment not found
- Role not found
- Superuser required to administer role assignments.
- Assignment already exists for this user/role/domain
AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14).
Data as JSON: /api/errors/006b152559598ccf.
Report an issue: GitHub.