{"record":{"id":"f097fc6049c8d35f","repo":"instructure/canvas-lms","slug":"user-user-id-didn-t-exist-for-is-tags-differentiation-tag","errorCode":null,"errorMessage":"User #{user_id} didn't exist for #{is_tags ? \"differentiation tag\" : \"group\"} user","messagePattern":"User #(.+?) didn't exist for #(.+?) user","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/group_membership_importer.rb","lineNumber":59,"sourceCode":"      end\n\n      def add_group_membership(user_id, group_id, status, is_tags: false)\n        user_id = user_id.to_s\n        group_id = group_id.to_s\n        raise ImportError, \"No #{is_tags ? \"tag_id\" : \"group_id\"} given for a #{is_tags ? \"differentiation tag\" : \"group\"} user\" if group_id.blank?\n        raise ImportError, \"No user_id given for a #{is_tags ? \"differentiation tag\" : \"group\"} user\" if user_id.blank?\n        raise ImportError, \"Improper status \\\"#{status}\\\" for a #{is_tags ? \"differentiation tag\" : \"group\"} user\" unless /\\A(accepted|deleted)/i.match?(status)\n        return if @batch.skip_deletes? && status =~ /deleted/i\n\n        pseudo = @root_account.pseudonyms.find_by(sis_user_id: user_id)\n        user = pseudo&.user\n\n        group = @groups_cache[group_id]\n        scope = is_tags ? @root_account.all_differentiation_tags : @root_account.all_groups\n        group ||= scope.where(sis_source_id: group_id).preload(:context).take\n        @groups_cache[group.sis_source_id] = group if group\n\n        raise ImportError, \"User #{user_id} didn't exist for #{is_tags ? \"differentiation tag\" : \"group\"} user\" unless user\n        raise ImportError, \"#{is_tags ? \"Differentiation tag\" : \"Group\"} #{group_id} didn't exist for #{is_tags ? \"differentiation tag\" : \"group\"} user\" unless group\n\n        if group.context.is_a?(Course) && !group.context.all_real_users.where(id: user.id).exists?\n          raise ImportError, \"User #{user_id} doesn't have an enrollment in the course of #{is_tags ? \"differentiation tag\" : \"group\"} #{group_id}.\"\n        end\n\n        if group && is_tags\n          raise ImportError, \"Differentiation Tags are not enabled for Account #{group.context.account.id}.\" unless group.context.account.allow_assign_to_differentiation_tags?\n        end\n\n        # can't query group.group_memberships, since that excludes deleted memberships\n        group_membership = GroupMembership.where(group_id: group, user_id: user)\n                                          .order(Arel.sql(\"CASE WHEN workflow_state = 'accepted' THEN 0 ELSE 1 END\")).take\n        group_membership ||= group.group_memberships.build(user:)\n\n        group_membership.sis_batch_id = @batch.id\n\n        case status","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/group_membership_importer.rb#L41-L77","documentation":"After resolving the pseudonym by sis_user_id, the importer raises if no user was found — i.e. the referenced user does not exist on this root account (or the pseudonym lookup failed), so the membership cannot be created.","triggerScenarios":"add_group_membership with a user_id whose pseudonym (sis_user_id) does not exist under @root_account; user was deleted; import run on the wrong root account/shard; users.csv not imported before group memberships.","commonSituations":"Cross-shard or multi-root-account SIS setups where the id lives on another account; typo in the SIS user id; users file processed after groups file out of order; user enrolled in a different root account.","solutions":["Ensure the user exists with that sis_user_id on the target root account (import users.csv first)","Check the sis_user_id spelling/case and that you are not using a Canvas numeric id where a SIS id is expected","Verify you are importing into the correct root account/shard","Create or re-activate the user's pseudonym before running the group membership import"],"exampleFix":"# before (user not yet imported)\ngroups_memberships.csv references u_500, users.csv absent\n# after\nimport users.csv creating pseudonym sis_user_id u_500, then run memberships","handlingStrategy":"validation","validationCode":"user_id_ok = root_account.pseudonyms.active.by_sis_user_id(user_id).exists?\nraise \"user #{user_id} not on this root account\" unless user_id_ok","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_group_membership(uid, gid, status)\nrescue SIS::GroupImporter::ImportError => e\n  raise unless e.message =~ /didn't exist for .*user/\n  Rails.logger.warn(\"Unknown user #{uid}; skipping row\")\nend","preventionTips":["Always import users.csv before group membership files","Confirm the target root account/shard matches where users live","Verify sis_user_id values (not canvas ids) are used in membership CSVs"],"tags":["sis-import","groups","user-not-found","data-consistency"],"backgroundTag":"user-not-found","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}