instructure/canvas-lms · error · ImportError
Enrollment # doesn't exist
Error message
Enrollment #{enrollment_id} doesn't exist What it means
After validating inputs, add_grade_publishing_result performs `Enrollment.where(id: enrollment_id, root_account_id: @root_account).update_all(...)` and raises ImportError when the affected row count is not exactly 1, meaning no enrollment with that id exists on this root account.
Solutions
- Verify the enrollment_id values are actual Enrollment#id values on the target root account
- Re-export the grade publishing results from the same account as the import target
- Filter the CSV against existing Enrollment ids before import: `Enrollment.where(id: ids).pluck(:id)`
- Check for cross-shard/account id mixing
Example fix
// before importer.add_grade_publishing_result(row['sis_enrollment_id'], status) // after enrollment = Enrollment.where(sis_source_id: row['sis_enrollment_id'], root_account_id: account).first importer.add_grade_publishing_result(enrollment.id, status) if enrollment
Defensive patterns
Strategy: validation
Validate before calling
valid_ids = Enrollment.where(id: ids, root_account_id: account).pluck(:id)
ids.each { |i| importer.add_grade_publishing_result(i, status) if valid_ids.include?(i) } Try / catch
begin
importer.add_grade_publishing_result(id, status)
rescue SIS::Base::ImportError => e
logger.warn("Enrollment missing: #{e.message}")
end Prevention
- Preflight-check all enrollment ids against the target account
- Never mix sis ids with numeric Enrollment ids
- Re-export from the same account/shard as the import target
When it happens
Trigger: Calling add_grade_publishing_result with an id that is not an existing Enrollment primary key, or an id belonging to a different root account than the one the importer was initialized with; stale/foreign enrollment ids from a previous or other-account import.
Common situations: CSV generated against a different Canvas account/shard; enrollment deleted between export and import; ids taken from sis ids instead of numeric Enrollment ids; test data referencing nonexistent enrollments.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Improper grade_publishing_status "#
- No enrollment_id given
- No grade_publishing_status given for enrollment #
- Not Found
- A student referenced a non-existent user #
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/07c5529ce565419d.
Report an issue: GitHub.
Appendix: source
Thrown at lib/sis/grade_publishing_results_importer.rb:48
attr_accessor :success_count
def initialize(batch, root_account, logger)
@batch = batch
@root_account = root_account
@logger = logger
@success_count = 0
end
def add_grade_publishing_result(enrollment_id, grade_publishing_status, message = nil)
raise ImportError, "No enrollment_id given" if enrollment_id.blank?
raise ImportError, "No grade_publishing_status given for enrollment #{enrollment_id}" if grade_publishing_status.blank?
raise ImportError, "Improper grade_publishing_status \"#{grade_publishing_status}\" for enrollment #{enrollment_id}" unless %w[published error].include?(grade_publishing_status.downcase)
if Enrollment.where(id: enrollment_id, root_account_id: @root_account)
.update_all(grade_publishing_status: grade_publishing_status.downcase,
grade_publishing_message: message.to_s,
updated_at: Time.now.utc) != 1
raise ImportError, "Enrollment #{enrollment_id} doesn't exist"
end
@success_count += 1
end
end
end
end
View on GitHub (pinned to 1c9f0bb801)