{"record":{"id":"5024eee6c291d23e","repo":"instructure/canvas-lms","slug":"only-one-context-is-allowed-and-both-course-id-and-account","errorCode":null,"errorMessage":"Only one context is allowed and both course_id and account_id where provided for #{type_display} #{sis_id}.","messagePattern":"Only one context is allowed and both course_id and account_id where provided for #(.+?) #(.+?)\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/group_category_importer.rb","lineNumber":57,"sourceCode":"        @roll_back_data = []\n        @accounts_cache = {}\n        @courses_cache = {}\n      end\n\n      def invalid_category?(sis_id, name, status, type_display)\n        raise ImportError, \"No sis_id given for a #{type_display}\" if sis_id.blank?\n        raise ImportError, \"No name given for #{type_display} #{sis_id}\" if name.blank?\n        raise ImportError, \"No status given for #{type_display} #{sis_id}\" if status.blank?\n        raise ImportError, \"Improper status \\\"#{status}\\\" for #{type_display} #{sis_id}, skipping\" unless /\\A(active|deleted)/i.match?(status)\n        return true if @batch.skip_deletes? && status =~ /deleted/i\n\n        false\n      end\n\n      def find_context(account_id, course_id, sis_id, type_display)\n        context = nil\n        if account_id && course_id\n          raise ImportError, \"Only one context is allowed and both course_id and account_id where provided for #{type_display} #{sis_id}.\"\n        end\n\n        if account_id\n          context = @accounts_cache[account_id]\n          context ||= @root_account.all_accounts.active.find_by(sis_source_id: account_id)\n          raise ImportError, \"Account with id \\\"#{account_id}\\\" didn't exist for #{type_display} #{sis_id}\" unless context\n\n          @accounts_cache[context.sis_source_id] = context\n        end\n\n        if course_id\n          context = @courses_cache[course_id]\n          context ||= @root_account.all_courses.active.find_by(sis_source_id: course_id)\n          raise ImportError, \"Course with id \\\"#{course_id}\\\" didn't exist for #{type_display} #{sis_id}\" unless context\n\n          @courses_cache[context.sis_source_id] = context\n        elsif course_id.nil? && type_display == \"differentiation tag set\"\n          raise ImportError, \"No course_id given for #{type_display} #{sis_id}\"","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/group_category_importer.rb#L39-L75","documentation":"find_context resolves exactly one owning context (Account or Course) for an imported group/category/tag. Supplying both course_id and account_id is ambiguous — the importer cannot decide where the record belongs — so it raises ImportError immediately.","triggerScenarios":"add_group_category(sis_id, account_id, course_id, name, status), add_group(...), add_tag(...) or add_differentiation_tag_set(...) called with both a non-nil account_id and a non-nil course_id (both columns populated in the CSV row).","commonSituations":"CSV export tools that always emit both account_id and course_id columns and fill both; manually adding a course_id to an account-level category row without clearing account_id.","solutions":["Populate only one of account_id / course_id for each row — leave the other blank.","If the category is course-scoped, clear the account_id column; if account-scoped, clear course_id.","Fix the exporter so account-level records omit course_id and vice versa."],"exampleFix":"// before (both columns set)\ngc-1,Math Groups,ACCOUNT-1,COURSE-7,active\n// after (course-scoped)\ngc-1,Math Groups,,COURSE-7,active","handlingStrategy":"validation","validationCode":"if account_id.present? && course_id.present?\n  raise ArgumentError, 'provide either account_id or course_id, not both'\nend","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_group(sis_id, acct_id, course_id, name, status)\nrescue SIS::GroupImporter::ImportError => e\n  notify(\"ambiguous context for #{sis_id}: #{e.message}\")\nend","preventionTips":["Configure exporters to emit exactly one of account_id/course_id per row","Run a pre-import lint that rejects rows with both columns populated","Document the either-or contract in CSV templates"],"tags":["sis","csv-import","validation","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","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"}