{"record":{"id":"524874931bfc3b29","repo":"instructure/canvas-lms","slug":"only-one-context-is-allowed-and-both-course-id-and-account-524874","errorCode":null,"errorMessage":"Only one context is allowed and both course_id and account_id where provided for group #{group_id}.","messagePattern":"Only one context is allowed and both course_id and account_id where provided for group #(.+?)\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/group_importer.rb","lineNumber":159,"sourceCode":"        same_context = new_context.id == item.context_id &&\n                       new_context.class.base_class.name == item.context_type\n\n        # For groups, we only block moves between courses, but allow other context changes\n        if !same_context &&\n           ((item.context.is_a?(Course) || new_context.is_a?(Course)) || item_type == \"differentiation_tag\")\n          raise ImportError, \"Cannot move #{type_display_name(item_type)} #{item_id} because it has #{item_type}_memberships.\"\n        end\n\n        true\n      end\n\n      public\n\n      def add_group(group_id, group_category_id, account_id, course_id, name, status)\n        return if invalid_import_item?(group_id, name, status, \"group\")\n\n        if course_id && account_id\n          raise ImportError, \"Only one context is allowed and both course_id and account_id where provided for group #{group_id}.\"\n        end\n\n        context = find_context(account_id, :account_id, \"group\", group_id) if account_id\n        context ||= find_context(course_id, :course_id, \"group\", group_id) if course_id\n\n        group_category = nil\n        if group_category_id.present?\n          group_category = find_category(group_category_id, context, :group_category, \"group\", group_id)\n        end\n\n        group = @root_account.all_groups.find_by(sis_source_id: group_id)\n\n        if group_category\n          context = group_category.context\n          if group\n            group.group_category = group_category\n          else\n            group = group_category.groups.new(name:, sis_source_id: group_id)","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/group_importer.rb#L141-L177","documentation":"Raised in add_group when both course_id and account_id are supplied for the same group row. A SIS group must belong to exactly one context, so specifying both is contradictory and rejected immediately after the basic field checks. The message contains a known typo ('where' for 'were').","triggerScenarios":"A groups row or programmatic add_group call that populates both the account_id and course_id values for one group_id.","commonSituations":"Generators that always emit both columns; merged exports from two sources; template rows pre-filled with example ids; copy/paste errors.","solutions":["Remove one value — keep course_id for course groups, account_id for account groups.","Configure the CSV generator to emit only the applicable context column.","Split the file into account-scoped and course-scoped rows.","Pre-validate the row: reject if both are present."],"exampleFix":"# before\ngroup_id,account_id,course_id,name,status\nG101,A100,C200,Study Group A,available\n# after\ngroup_id,course_id,name,status\nG101,C200,Study Group A,available","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'provide either account_id or course_id, not both' if account_id.present? && course_id.present?","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_group(gid, cat_id, acct_id, course_id, name, status)\nrescue ImportError => e\n  logger.warn(\"Conflicting context columns: #{e.message}\")\nend","preventionTips":["Emit only one context column per row from your CSV writer","Validate rows with an exactly-one-of account_id/course_id schema","Split account-scoped and course-scoped groups into separate files","Clean template rows that prefill both columns"],"tags":["sis-import","conflicting-arguments","csv-validation"],"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"}