{"record":{"id":"a8443703de18f34a","repo":"instructure/canvas-lms","slug":"invalid-fields-for-a-group-invalid","errorCode":null,"errorMessage":"Invalid fields for a group: %{invalid}","messagePattern":"Invalid fields for a group: %(.+?)","errorType":"validation","errorClass":"InvalidDataError","httpStatus":null,"severity":"error","filePath":"lib/outcomes/import.rb","lineNumber":77,"sourceCode":"      when \"outcome\"\n        import_outcome(object)\n      when \"group\"\n        import_group(object)\n      else\n        raise InvalidDataError, I18n.t(\n          'Invalid %{field}: \"%{type}\"',\n          field: \"object_type\",\n          type:\n        )\n      end\n    end\n\n    def import_group(group)\n      invalid = group.keys.select do |k|\n        group[k].present? && OBJECT_ONLY_FIELDS.include?(k)\n      end\n      if invalid.present?\n        raise InvalidDataError, I18n.t(\n          \"Invalid fields for a group: %{invalid}\",\n          invalid: invalid.map(&:to_s).inspect\n        )\n      end\n\n      group_context = context\n\n      if group[:course_id].present?\n        raise InvalidDataError, I18n.t(\"Cannot import to other courses\") unless context.is_a?(Account)\n\n        group_context = Course.find_by(id: group[:course_id])\n\n        if group_context.nil?\n          raise InvalidDataError, I18n.t(\n            \"Course with canvas id %{id} not found\",\n            id: group[:course_id]\n          )\n        end","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/outcomes/import.rb#L59-L95","documentation":"import_group rejects group objects that carry fields reserved for outcomes only: calculation_method, calculation_int, or ratings (OBJECT_ONLY_FIELDS). If any of these keys are present with a present? (non-blank) value, the group import aborts with this error listing the offending keys. Groups (LearningOutcomeGroup) have no mastery calculation, so these fields are meaningless there.","triggerScenarios":"Calling import_object with object_type 'group' and e.g. {ratings: [{points: 3}]}, {calculation_method: 'highest'}, or {calculation_int: 79} set. Only non-blank values trigger it; empty strings/nil for these keys pass.","commonSituations":"Reusing one row/schema for both outcomes and groups and exporting all columns; CSV imports where the outcome-only columns are populated on group rows; client libraries that serialize a full outcome object even when importing a group.","solutions":["Remove calculation_method, calculation_int, and ratings from group objects.","If your source rows share a schema, blank out these keys (nil or '') for rows where object_type is 'group'.","Pre-validate rows and route: outcome-only fields imply the row should be imported as an 'outcome'."],"exampleFix":"// before\n{ object_type: 'group', title: 'Math', ratings: [{points: 3}] }\n// after\n{ object_type: 'group', title: 'Math' }","handlingStrategy":"validation","validationCode":"OBJECT_ONLY = %i[calculation_method calculation_int ratings]\nbad = OBJECT_ONLY.select { |k| group[k].present? }\nraise ArgumentError, \"group rows cannot set #{bad}\" if bad.any?","typeGuard":"def group_only?(obj)\n  obj.is_a?(Hash) && %i[calculation_method calculation_int ratings].none? { |k| obj[k].present? }\nend","tryCatchPattern":"begin\n  importer.import_object(object)\nrescue Outcomes::Import::InvalidDataError => e\n  Rails.logger.warn(\"bad group row #{object[:vendor_guid]}: #{e.message}\")\nend","preventionTips":["Use separate schemas/serializers for group and outcome rows","Blank outcome-only columns for group rows in shared CSVs","Lint import files for illegal key/type combos before import"],"tags":["validation","schema","outcomes-import","payload"],"backgroundTag":"schema-validation-failed","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"}