{"record":{"id":"df3bfca454616dfa","repo":"instructure/canvas-lms","slug":"dont-use-this-use-short-name-instead-group","errorCode":null,"errorMessage":"DONT USE THIS, use .short_name instead","messagePattern":"DONT USE THIS, use \\.short_name instead","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/models/group.rb","lineNumber":230,"sourceCode":"  def free_association?(user)\n    auto_accept? || allow_join_request? || allow_self_signup?(user)\n  end\n\n  def allow_student_forum_attachments\n    context.respond_to?(:allow_student_forum_attachments) && context.allow_student_forum_attachments\n  end\n\n  def participants(opts = {})\n    users = participating_users.distinct.all\n    if opts[:include_observers] && context.is_a?(Course)\n      (users + User.observing_students_in_course(users, context)).flatten.uniq\n    else\n      users\n    end\n  end\n\n  def context_code\n    raise \"DONT USE THIS, use .short_name instead\" unless Rails.env.production?\n  end\n\n  def inactive?\n    context.deleted? || (context.is_a?(Course) && context.inactive?)\n  end\n\n  def context_available?\n    return false unless context\n\n    case context\n    when Course\n      context.available? && (!context.respond_to?(:concluded?) || !context.concluded?)\n    else\n      true\n    end\n  end\n\n  def appointment_context_codes","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/group.rb#L212-L248","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace calls to group.context_code with group.short_name (or the appropriate context_type/context_id pairing)","Update views/partials and plugin code that render context_code for groups","In specs, fix assertions to use short_name so tests exercise the supported API","If you must probe it, check the env — only production returns without raising"],"exampleFix":"// before\nlabel = group.context_code\n// after\nlabel = group.short_name","handlingStrategy":"try-catch","validationCode":"label = group.respond_to?(:short_name) ? group.short_name : group.name","typeGuard":null,"tryCatchPattern":"begin\n  label = group.context_code\nrescue RuntimeError => e\n  raise unless e.message =~ /short_name/\n  label = group.short_name\nend","preventionTips":["Never call context_code on Group; use short_name","Grep codebases/plugins for `group.context_code` during upgrades","Run test suites in dev to surface this tripwire before production"],"tags":["ruby","rails","deprecation","groups","api-migration"],"backgroundTag":"deprecated-api-usage","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}