instructure/canvas-lms · error · ImportError

Improper grade_publishing_status "#

Error message

Improper grade_publishing_status "#{grade_publishing_status}" for enrollment #{enrollment_id}

What it means

add_grade_publishing_result raises ImportError when grade_publishing_status is not one of the allowed values 'published' or 'error' (compared case-insensitively after downcase). Any other string is rejected with the offending value interpolated.

Solutions

  1. Normalize source statuses to exactly 'published' or 'error' before import
  2. Map foreign status vocabularies (e.g. success→published, failure→error) in preprocessing
  3. Verify no stray whitespace: use `status.strip.downcase` when producing the value

Example fix

// before
importer.add_grade_publishing_result(id, 'success')
// after
mapped = { 'success' => 'published', 'failure' => 'error' }.fetch(row['status'].downcase, 'error')
importer.add_grade_publishing_result(id, mapped)
Defensive patterns

Strategy: validation

Validate before calling

raise 'bad status' unless %w[published error].include?(grade_publishing_status.to_s.strip.downcase)

Try / catch

begin
  importer.add_grade_publishing_result(id, status)
rescue SIS::Base::ImportError => e
  logger.warn("Skipping grade publishing result: #{e.message}")
end

Prevention

When it happens

Trigger: Calling `add_grade_publishing_result(id, 'pending', msg)` or 'failed', 'publishing', etc.; CSV status column containing values from a foreign vocabulary.

Common situations: Producer system emits statuses like 'in_progress', 'success', 'unpublished'; typos ('pubished'); whitespace-padded values with trailing spaces if not trimmed (whitespace still fails the %w[] include).

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/75de06d342a88ee5. Report an issue: GitHub.

Appendix: source

Thrown at lib/sis/grade_publishing_results_importer.rb:42

      importer = Work.new(@batch, @root_account, @logger)
      yield importer
      importer.success_count
    end

    class Work
      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)