instructure/canvas-lms · error · RuntimeError

invalid restriction type

Error message

invalid restriction type

What it means

MasterCourses::Restrictor.restrict_columns validates that edit_type is one of MasterCourses::LOCK_TYPES (e.g. :content, :state, :points, :due_dates, :availability, :settings). Passing any other symbol raises 'invalid restriction type' before any columns are recorded.

Solutions

  1. Use only lock types in MasterCourses::LOCK_TYPES (check lib/master_courses.rb)
  2. Fix the symbol typo in the restrict_columns call
  3. If a new category is genuinely needed, add it to MasterCourses::LOCK_TYPES and handle it in downstream code

Example fix

// before
restrict_columns(:attributes, [:title])
// after
restrict_columns(:content, [:title])
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError unless MasterCourses::LOCK_TYPES.include?(edit_type)
restrict_columns(edit_type, columns)

Type guard

def valid_lock_type?(t)
  MasterCourses::LOCK_TYPES.include?(t.to_sym)
end

Try / catch

begin
  model.restrict_columns(edit_type, cols)
rescue RuntimeError => e
  raise unless e.message == 'invalid restriction type'
  Rails.logger.warn("bad edit type #{edit_type}")
end

Prevention

When it happens

Trigger: Calling restrict_columns(:some_edit_type, :col) with a symbol not in MasterCourses::LOCK_TYPES, often a typo or an invented restriction category, from a model's restrict_*_columns helper (e.g. restrict_assignment_columns).

Common situations: Typo like :attributes instead of :content; adding a custom edit type without registering it in LOCK_TYPES; upgrading Canvas where a lock type was renamed.

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/cf0c268f9dd89ead. Report an issue: GitHub.

Appendix: source

Thrown at app/models/master_courses/restrictor.rb:63

    klass.after_update :mark_downstream_changes

    # luckily before_update comes after before_save in case we do sneaky changes in models
    klass.before_update :check_before_overwriting_child_content_on_import
  end

  module CommonMethods # i didn't want to copypaste all this into the collection one
    def self.included(klass)
      klass.cattr_accessor :restricted_column_settings
      klass.restricted_column_settings = {}

      klass.extend ClassMethods
      klass.validate :check_for_restricted_column_changes
    end

    module ClassMethods
      def restrict_columns(edit_type, columns)
        raise "invalid restriction type" unless MasterCourses::LOCK_TYPES.include?(edit_type)

        columns = Array(columns).map(&:to_s)
        current = restricted_column_settings[edit_type] || []
        restricted_column_settings[edit_type] = (current + columns).uniq
      end

      def restrict_assignment_columns
        restrict_columns :settings, %i[assignment_group_id
                                       grading_type
                                       omit_from_final_grade
                                       submission_types
                                       group_category
                                       group_category_id
                                       grade_group_students_individually
                                       peer_reviews
                                       moderated_grading
                                       peer_reviews_due_at
                                       allowed_attempts]

View on GitHub (pinned to 1c9f0bb801)