instructure/canvas-lms · warning

DONT USE THIS, use .short_name instead

Error message

DONT USE THIS, use .short_name instead

What it means

Course#context_code has a guard that raises in every environment except production, steering developers to use short_name instead. The method intentionally only keeps its legacy behavior in production as a deprecation safety net.

Solutions

  1. Replace calls with course.short_name (which produces the same 'course_<id>' style code via the standard context convention)
  2. Use the object's asset string, e.g. "course_#{course.id}", if you specifically need the context code format
  3. Guard the call with Rails.env.production? only if legacy parity is truly required

Example fix

// before
code = course.context_code
// after
code = course.short_name
Defensive patterns

Strategy: type-guard

Validate before calling

code = Rails.env.production? ? course.context_code : course.short_name

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Calling course.context_code in development/test/staging environments instead of course.short_name.

Common situations: Copying old code that used context_code; writing specs or dev-console scripts that reference context_code and hitting the raise outside production.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at app/models/course.rb:1849

    elsif self.syllabus_master_template_id
      self.syllabus_master_template_id = nil
    end
  end

  def attachment_associations_enabled?
    root_account.feature_enabled?(:disable_file_verifiers_in_public_syllabus)
  end

  def access_for_attachment_association?(user, session, _association)
    grants_right?(user, session, :read_syllabus)
  end

  def home_page
    wiki.front_page
  end

  def context_code
    raise "DONT USE THIS, use .short_name instead" unless Rails.env.production?
  end

  def allow_media_comments?
    true
  end

  def short_name_slug
    CanvasTextHelper.truncate_text(short_name, ellipsis: "")
  end

  # Allows the account to be set directly
  belongs_to :account

  def discussion_checkpoints_enabled?
    account&.discussion_checkpoints_enabled?
  end

  def wiki

View on GitHub (pinned to 1c9f0bb801)