{"record":{"id":"6bf49548ae7b6b43","repo":"SigNoz/signoz","slug":"errcoderolehasuserassignees","errorCode":"ErrCodeRoleHasUserAssignees","errorMessage":"role has active user assignments, remove them before deleting","messagePattern":"role has active user assignments, remove them before deleting","errorType":"error_code","errorClass":"errors.Error","httpStatus":400,"severity":"error","filePath":"pkg/modules/user/impluser/getter.go","lineNumber":157,"sourceCode":"\tresetPasswordToken, err := module.store.GetResetPasswordToken(ctx, token)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif resetPasswordToken.IsExpired() {\n\t\treturn errors.New(errors.TypeUnauthenticated, types.ErrCodeResetPasswordTokenExpired, \"reset password token has expired\")\n\t}\n\n\treturn nil\n}\n\nfunc (module *getter) OnBeforeRoleDelete(ctx context.Context, orgID valuer.UUID, roleID valuer.UUID, _ string) error {\n\tusers, err := module.GetUsersByOrgIDAndRoleID(ctx, orgID, roleID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(users) > 0 {\n\t\treturn errors.New(errors.TypeInvalidInput, authtypes.ErrCodeRoleHasUserAssignees, \"role has active user assignments, remove them before deleting\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":139,"sourceCodeEnd":161,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/modules/user/impluser/getter.go#L139-L161","documentation":"Pre-delete hook fired when attempting to delete a role: the role is still assigned to at least one user in the org (GetUsersByOrgIDAndRoleID returns rows), so deletion is blocked to avoid orphaned assignments.","triggerScenarios":"DELETE on a role (e.g. DELETE /api/v1/roles/{id} or the role delete API) while any user in the org still has that role assigned.","commonSituations":"Bulk user imports that assigned default roles; leftover assignments after offboarding; attempting to clean up roles before unassigning users.","solutions":["List users assigned to the role (GetUsersByOrgIDAndRoleID / the user-role listing API) and remove the role from each user","Reassign affected users to a replacement role, then retry the role delete","Automate the check in a pre-deletion script so role cleanup is never attempted with active assignees"],"exampleFix":"// before\ndeleteRole(orgID, roleID) // fails\n// after\nusers := getUsersByOrgIDAndRoleID(orgID, roleID)\nfor _, u := range users { removeUserRole(orgID, u.ID, roleID) }\ndeleteRole(orgID, roleID)","handlingStrategy":"validation","validationCode":"users, _ := getUsersByOrgIDAndRoleID(ctx, orgID, roleID)\nif len(users) > 0 {\n    // unassign or reassign before delete\n    return fmt.Errorf(\"role in use by %d users\", len(users))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run the assignee check before role deletion in admin tooling","Make role removal part of the user offboarding pipeline"],"tags":["roles","delete-guard","referential-integrity","user-module"],"backgroundTag":"resource-in-use","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}