{"record":{"id":"59bf6d0ef0479e9a","repo":"instructure/canvas-lms","slug":"a-type-display-name-item-type-did-not-pass-validation-item","errorCode":null,"errorMessage":"A #{type_display_name(item_type)} did not pass validation (#{item_type}: #{item.sis_source_id}, error: #{item.errors.full_messages.join(\",\")})","messagePattern":"A #(.+?) did not pass validation \\(#(.+?): #(.+?), error: #(.+?)\\)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/group_importer.rb","lineNumber":130,"sourceCode":"          data = SisBatchRollBackData.build_data(sis_batch: @batch, context: item)\n          @roll_back_data << data if data\n\n          if status == \"deleted\"\n            gms = SisBatchRollBackData.build_dependent_data(\n              sis_batch: @batch,\n              contexts: item.group_memberships,\n              updated_state: \"deleted\"\n            )\n            @roll_back_data.push(*gms) if gms\n          end\n\n          @success_count += 1\n          true\n        else\n          msg = \"A #{type_display_name(item_type)} did not pass validation \"\n          msg += \"(\" + \"#{item_type}: #{item.sis_source_id}, error: \"\n          msg += item.errors.full_messages.join(\",\") + \")\"\n          raise ImportError, msg\n        end\n      end\n\n      def can_change_context?(item, new_context, item_type, item_id)\n        if item_type == \"differentiation_tag\"\n          raise ImportError, \"Differentiation Tags are not enabled for Account #{context.account.id}.\" unless new_context.account.allow_assign_to_differentiation_tags?\n        end\n\n        return true unless item&.group_memberships&.exists?\n\n        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","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/group_importer.rb#L112-L148","documentation":"Raised in save_and_process_memberships when the Group or GroupCategory record fails ActiveRecord validations on save. CSV-level checks passed, but the resulting model is invalid; the model's error messages are joined into the raised message.","triggerScenarios":"add_group/add_tag rows whose values violate model validations at save time — e.g. name exceeding length limits or uniqueness constraints within a category.","commonSituations":"Names longer than the DB/validator limit; duplicate names within a category; oversized fields from data migrations; new validations added by upgrades that legacy CSVs violate.","solutions":["Read the embedded error list in the message and fix the offending field.","Truncate names to fit length validations.","Resolve uniqueness conflicts before import.","Build the item locally and call valid? to identify failing validations."],"exampleFix":"# before: 300-char name -> \"Name is too long\"\nitem.name = long_name\nitem.save\n# after\nitem.name = long_name[0, 255]\nitem.save","handlingStrategy":"validation","validationCode":"name = name.to_s\nraise ArgumentError, 'name too long (max 255)' if name.length > 255\nraise ArgumentError, 'name blank' if name.strip.empty?","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_group(gid, cat_id, acct_id, course_id, name, status)\nrescue ImportError => e\n  logger.warn(\"Model validation failed: #{e.message}\")\nend","preventionTips":["Truncate long fields to model limits before export","Build the model in a dry-run and call valid? early","Watch for new validations added by upgrades/plugins","Deduplicate names within a category pre-import"],"tags":["sis-import","validation","activerecord"],"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"}