{"record":{"id":"d116aadfd329d800","repo":"instructure/canvas-lms","slug":"group-category-ids-do-not-match","errorCode":null,"errorMessage":"Group category IDs do not match","messagePattern":"Group category IDs do not match","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/update_discussion_topic.rb","lineNumber":287,"sourceCode":"    validate_and_remove_group_category_id(assignment_params, discussion_topic) if assignment_params.key?(:group_category_id)\n\n    # If a topic doesn't have a group_category_id or has submissions, then the assignment group_category_id should be nil\n    unless discussion_topic.try(:group_category_id) || assignment.has_submitted_submissions?\n      assignment_params[:group_category_id] = nil\n    end\n\n    # Finalize assignment restoration\n    discussion_topic.assignment = assignment\n    discussion_topic.sync_assignment\n    # This save is required to prevent an extra discussion_topic from being created in the updateAssignment\n    assignment.updating_user = current_user\n    assignment.save!\n  end\nend\n\ndef validate_and_remove_group_category_id(assignment_params, discussion_topic)\n  if assignment_params[:group_category_id].present? && discussion_topic.group_category_id.present? && assignment_params[:group_category_id] != discussion_topic.group_category_id.to_s\n    raise ArgumentError, \"Group category IDs do not match\"\n  end\n\n  if assignment_params[:group_category_id].present?\n    assignment_params.delete(:group_category_id)\n  end\nend\n","sourceCodeStart":269,"sourceCodeEnd":294,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/update_discussion_topic.rb#L269-L294","documentation":"validate_and_remove_group_category_id raises ArgumentError \"Group category IDs do not match\" when assignment_params[:group_category_id] is present, the discussion topic already has a group_category_id, and the two differ (string-vs-integer compared via to_s). resolve wraps this into a user-facing ExecutionError; it guards against silently re-pointing a group discussion's assignment at a different group set.","triggerScenarios":"set_discussion_assignment_association -> validate_and_remove_group_category_id during updateDiscussionTopic when the assignment input carries a groupCategoryId different from the topic's; also triggered by type mismatch (\"5\" vs 5 style comparisons if to_s were omitted elsewhere) though here to_s normalizes.","commonSituations":"Instructor changes group set on a group discussion that already has an assignment; external tools syncing assignments with their own group category; scripted migrations copying assignment payloads between topics.","solutions":["Send the topic's current group_category_id (as string) in the assignment params, or omit it.","Remove/recreate the assignment separately if the group set genuinely must change.","Delete the topic's group_category_id first (convert to non-group discussion), then re-add with the new group set and assignment.","Normalize both IDs to strings before comparing if you hit this in modified code."],"exampleFix":"// before\nif assignment_params[:group_category_id] != discussion_topic.group_category_id.to_s\n  raise ArgumentError, \"Group category IDs do not match\"\nend\n// after\nif assignment_params[:group_category_id].to_s != discussion_topic.group_category_id.to_s\n  raise ArgumentError, \"Group category IDs do not match\"\nend","handlingStrategy":"validation","validationCode":"const topicGcid = discussionTopic.group_category_id&.to_s\nif assignment_params[:group_category_id].present? && topicGcid.present? && assignment_params[:group_category_id].to_s != topicGcid\n  raise ArgumentError, 'Group category IDs do not match'\nend","typeGuard":"function sameGroupCategory(a, b) { return a == null || b == null || String(a) === String(b); }","tryCatchPattern":"begin\n  update_topic_with_assignment(params)\nrescue ArgumentError => e\n  raise GraphQL::ExecutionError, e.message if e.message.include?('Group category')\n  raise\nend","preventionTips":["Normalize IDs with to_s before equality checks","Only include group_category_id in assignment params when it matches the topic","Clear the topic's group set before switching to a new one","Add unit tests for string/integer ID comparison"],"tags":["graphql","assignments","group-categories"],"backgroundTag":"invalid-argument-value","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"}