{"record":{"id":"1f596ec89ab86606","repo":"langflow-ai/langflow","slug":"user-id-not-found","errorCode":null,"errorMessage":"user_id not found","messagePattern":"user_id not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"src/backend/base/langflow/api/v1/authz_role_assignments.py","lineNumber":96,"sourceCode":"        stmt = stmt.where(AuthzRoleAssignment.domain_id == domain_id)\n    stmt = stmt.order_by(AuthzRoleAssignment.assigned_at.desc(), AuthzRoleAssignment.id).offset(offset).limit(limit)\n    rows = (await session.exec(stmt)).all()\n    return [RoleAssignmentRead.model_validate(row) for row in rows]\n\n\n@router.post(\"\", response_model=RoleAssignmentRead, status_code=status.HTTP_201_CREATED)\n@router.post(\"/\", response_model=RoleAssignmentRead, status_code=status.HTTP_201_CREATED)\nasync def create_assignment(\n    payload: RoleAssignmentCreate,\n    current_user: CurrentActiveUser,\n    session: DbSession,\n) -> RoleAssignmentRead:\n    \"\"\"Assign a role to a user. Superuser-only.\"\"\"\n    _require_superuser(current_user)\n\n    user = await session.get(User, payload.user_id)\n    if user is None:\n        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=\"user_id not found\")\n    role = await session.get(AuthzRole, payload.role_id)\n    if role is None:\n        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=\"role_id not found\")\n\n    assignment = AuthzRoleAssignment(\n        user_id=payload.user_id,\n        role_id=payload.role_id,\n        domain_type=payload.domain_type,\n        domain_id=payload.domain_id,\n        assigned_at=datetime.now(timezone.utc),\n        assigned_by=current_user.id,\n    )\n    session.add(assignment)\n    try:\n        await session.commit()\n    except IntegrityError as exc:\n        await session.rollback()\n        raise HTTPException(","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/authz_role_assignments.py#L78-L114","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Re-fetch the current user list (GET /api/v1/users) and use a live id","If scripting, look the user up by username first and derive the id at runtime","Confirm you are pointed at the correct environment/database","Handle 404 non-retryable: surface 'user does not exist' rather than retrying"],"exampleFix":"// before\nawait api.post('/authz/role-assignments', { user_id: ' stale-uuid', role_id });\n\n// after\nconst users = await api.get('/api/v1/users');\nconst u = users.find(x => x.username === 'alice');\nif (!u) throw new Error('user not found');\nawait api.post('/authz/role-assignments', { user_id: u.id, role_id });","handlingStrategy":"validation","validationCode":"const users = await api.get('/api/v1/users');\nconst target = users.find(u => u.id === payload.user_id);\nif (!target) throw new Error('user does not exist');","typeGuard":"const isUuid = (v: string): boolean =>\n  /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v);","tryCatchPattern":"catch (e) { if (e.status === 404) showFormError('Selected user no longer exists'); }","preventionTips":["Resolve user ids at runtime by username instead of hard-coding UUIDs","Re-validate referenced ids right before submit in long-lived forms","Never auto-retry a 404 — fix the payload"],"tags":["authz","rbac","http-404","role-assignments"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}