{"record":{"id":"84131e93cb57ed7e","repo":"instructure/canvas-lms","slug":"no-tag-set-id-or-course-id-given-for-differentiation-tag-tag","errorCode":null,"errorMessage":"No tag_set_id or course_id given for differentiation tag #{tag_id}. At least one is required for new tags.","messagePattern":"No tag_set_id or course_id given for differentiation tag #(.+?)\\. At least one is required for new tags\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/group_importer.rb","lineNumber":228,"sourceCode":"        if tag_set_id.present?\n          tag_set = find_category(tag_set_id, context, :differentiation_tag_category, \"differentiation_tag\", tag_id)\n        end\n\n        tag = @root_account.all_differentiation_tags.find_by(sis_source_id: tag_id)\n\n        if tag_set\n          context = tag_set.context\n          raise ImportError, \"Differentiation Tags are not enabled for Account #{context.account.id}.\" unless context.account.allow_assign_to_differentiation_tags?\n\n          if tag\n            tag.group_category = tag_set\n          else\n            tag = tag_set.groups.non_collaborative.new(name:, sis_source_id: tag_id)\n          end\n        end\n\n        context ||= tag&.context\n        raise ImportError, \"No tag_set_id or course_id given for differentiation tag #{tag_id}. At least one is required for new tags.\" unless context\n\n        can_change_context?(tag, context, \"differentiation_tag\", tag_id)\n\n        tag ||= context.groups.new(name:, non_collaborative: true, sis_source_id: tag_id)\n        tag.name = name if name.present? && !tag.stuck_sis_fields.include?(:name)\n        tag.context = context\n        tag.sis_batch_id = @batch.id\n        tag.workflow_state = (status == \"deleted\") ? \"deleted\" : \"available\"\n\n        # Ensure tag category context matches tag context\n        if tag&.group_category &&\n           tag.group_category.context_id != context.id &&\n           tag.group_category.context_type == context.class_name\n          tag.group_category.update!(context_id: context.id)\n        else\n          tag_set ||= context.differentiation_tag_categories.create!(name:, non_collaborative: true)\n          # If adding as a single tag, have the tag set match the single tag status\n          tag_set.destroy if status == \"deleted\"","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/group_importer.rb#L210-L246","documentation":"add_tag resolves the tag's context either from an explicit tag_set (tag_set_id) or from a course_id. If neither a tag_set nor a course_id was supplied and the tag referenced by tag_id cannot be found (so no context can be inferred), the importer raises because it has no context in which to create the new differentiation tag.","triggerScenarios":"add_tag called with a tag_id that does not match an existing tag (so tag&.context is nil) and with neither tag_set_id nor course_id provided in the row.","commonSituations":"SIS CSV groups file for differentiation tags missing course_id column while using a new tag_id (creation attempt); typo in tag_id so the existing-tag lookup misses; importer invoked programmatically without context parameters.","solutions":["Add a course_id (or tag_set_id) to the SIS row so the tag has a context","Correct the tag_id so it matches an existing tag whose context can be used","If the import is API/console-driven, pass tag_set_id or course_id to add_tag","Validate the CSV before upload: every new tag row must include at least one of tag_set_id or course_id"],"exampleFix":"# before (CSV row)\n\"tag_123,,New Tag\"            # no tag_set_id, no course_id\n# after\n\"tag_123,C123,New Tag\"        # course_id supplied","handlingStrategy":"validation","validationCode":"raise 'tag row needs tag_set_id or course_id' if tag_set_id.blank? && course_id.blank?\n# or in CSV lint: require at least one of the two columns for every new tag_id","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_tag(tag_id, name, tag_set_id: tsid, course_id: cid)\nrescue SIS::GroupImporter::ImportError => e\n  raise unless e.message =~ /No tag_set_id or course_id given/\n  Rails.logger.error(\"Tag row missing context: #{e.message}\")\nend","preventionTips":["Require course_id or tag_set_id in every new-tag CSV row via a pre-import validator","Verify tag_ids of existing tags before relying on context inference","Keep a single CSV template that always includes both columns"],"tags":["sis-import","differentiation-tags","missing-argument","rails"],"backgroundTag":"missing-required-argument","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"}