{"record":{"id":"d06a573ae68a1cc7","repo":"instructure/canvas-lms","slug":"dont-use-this-use-short-name-instead","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/course.rb","lineNumber":1849,"sourceCode":"    elsif self.syllabus_master_template_id\n      self.syllabus_master_template_id = nil\n    end\n  end\n\n  def attachment_associations_enabled?\n    root_account.feature_enabled?(:disable_file_verifiers_in_public_syllabus)\n  end\n\n  def access_for_attachment_association?(user, session, _association)\n    grants_right?(user, session, :read_syllabus)\n  end\n\n  def home_page\n    wiki.front_page\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 allow_media_comments?\n    true\n  end\n\n  def short_name_slug\n    CanvasTextHelper.truncate_text(short_name, ellipsis: \"\")\n  end\n\n  # Allows the account to be set directly\n  belongs_to :account\n\n  def discussion_checkpoints_enabled?\n    account&.discussion_checkpoints_enabled?\n  end\n\n  def wiki","sourceCodeStart":1831,"sourceCodeEnd":1867,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/course.rb#L1831-L1867","documentation":"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.","triggerScenarios":"Calling course.context_code in development/test/staging environments instead of course.short_name.","commonSituations":"Copying old code that used context_code; writing specs or dev-console scripts that reference context_code and hitting the raise outside production.","solutions":["Replace calls with course.short_name (which produces the same 'course_<id>' style code via the standard context convention)","Use the object's asset string, e.g. \"course_#{course.id}\", if you specifically need the context code format","Guard the call with Rails.env.production? only if legacy parity is truly required"],"exampleFix":"// before\ncode = course.context_code\n// after\ncode = course.short_name","handlingStrategy":"type-guard","validationCode":"code = Rails.env.production? ? course.context_code : course.short_name","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Always use short_name for context codes","Grep codebases for context_code usages when upgrading","Use asset_string helpers (\"course_#{id}\") for context codes"],"tags":["ruby","rails","deprecation","course"],"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"}