instructure/canvas-lms · warning

DONT USE THIS, use .short_name instead

Error message

DONT USE THIS, use .short_name instead

What it means

Group#context_code is deliberately poisoned in non-production environments: it raises 'DONT USE THIS, use .short_name instead' to smoke out code still relying on this legacy method. In production it silently returns nil (no body), so the raise is a dev/test-time deprecation tripwire.

Solutions

  1. Replace calls to group.context_code with group.short_name (or the appropriate context_type/context_id pairing)
  2. Update views/partials and plugin code that render context_code for groups
  3. In specs, fix assertions to use short_name so tests exercise the supported API
  4. If you must probe it, check the env — only production returns without raising

Example fix

// before
label = group.context_code
// after
label = group.short_name
Defensive patterns

Strategy: try-catch

Validate before calling

label = group.respond_to?(:short_name) ? group.short_name : group.name

Try / catch

begin
  label = group.context_code
rescue RuntimeError => e
  raise unless e.message =~ /short_name/
  label = group.short_name
end

Prevention

When it happens

Trigger: Calling group.context_code in development/test (Rails.env != production) from application code, views, specs, or console — anywhere the deprecated method is still referenced outside production.

Common situations: Specs or local dev hitting a view/template that still calls context_code on Group; plugins or older code paths not migrated to short_name; console introspection in development.

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

Appendix: source

Thrown at app/models/group.rb:230

  def free_association?(user)
    auto_accept? || allow_join_request? || allow_self_signup?(user)
  end

  def allow_student_forum_attachments
    context.respond_to?(:allow_student_forum_attachments) && context.allow_student_forum_attachments
  end

  def participants(opts = {})
    users = participating_users.distinct.all
    if opts[:include_observers] && context.is_a?(Course)
      (users + User.observing_students_in_course(users, context)).flatten.uniq
    else
      users
    end
  end

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

  def inactive?
    context.deleted? || (context.is_a?(Course) && context.inactive?)
  end

  def context_available?
    return false unless context

    case context
    when Course
      context.available? && (!context.respond_to?(:concluded?) || !context.concluded?)
    else
      true
    end
  end

  def appointment_context_codes

View on GitHub (pinned to 1c9f0bb801)