{"record":{"id":"f72e0f341130af3d","repo":"instructure/canvas-lms","slug":"selectedcourse-must-be-all-or-course-id","errorCode":null,"errorMessage":"selectedCourse must be 'all' or 'course_{id}'","messagePattern":"selectedCourse must be 'all' or 'course_(.+?)'","errorType":"validation","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/update_widget_dashboard_config.rb","lineNumber":130,"sourceCode":"  def validate_todo_list_filters!(filters)\n    if filters.key?(\"filter\")\n      filter_value = filters[\"filter\"]\n      unless filter_value.is_a?(String) && VALID_TODO_FILTERS.include?(filter_value)\n        raise GraphQL::ExecutionError, \"filter must be one of: #{VALID_TODO_FILTERS.join(\", \")}\"\n      end\n    end\n\n    invalid_keys = filters.keys - [\"filter\"]\n    unless invalid_keys.empty?\n      raise GraphQL::ExecutionError, \"invalid filter keys for todo list widget: #{invalid_keys.join(\", \")}\"\n    end\n  end\n\n  def validate_course_work_filters!(filters)\n    if filters.key?(\"selectedCourse\")\n      course_value = filters[\"selectedCourse\"]\n      unless course_value.is_a?(String) && (course_value == \"all\" || course_value.match?(/^course_\\d+$/))\n        raise GraphQL::ExecutionError, \"selectedCourse must be 'all' or 'course_{id}'\"\n      end\n    end\n\n    if filters.key?(\"selectedDateFilter\")\n      date_filter = filters[\"selectedDateFilter\"]\n      unless date_filter.is_a?(String) && VALID_DATE_FILTERS.include?(date_filter)\n        raise GraphQL::ExecutionError, \"selectedDateFilter must be one of: #{VALID_DATE_FILTERS.join(\", \")}\"\n      end\n    end\n\n    invalid_keys = filters.keys - [\"selectedCourse\", \"selectedDateFilter\"]\n    unless invalid_keys.empty?\n      raise GraphQL::ExecutionError, \"invalid filter keys for course work widget: #{invalid_keys.join(\", \")}\"\n    end\n  end\n\n  def validate_generic_filters!(filters)\n    filters.each_value do |value|","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/update_widget_dashboard_config.rb#L112-L148","documentation":"The course work widget accepts a \"selectedCourse\" filter that must be either the literal string \"all\" or a string matching /^course_\\d+$/ (e.g. \"course_42\"). validate_course_work_filters! raises this GraphQL::ExecutionError for any other value, including bare numeric IDs or non-string types.","triggerScenarios":"Sending filters[\"selectedCourse\"] = 42 (integer), \"42\", \"course_abc\", \"Course_42\", \"\", or null for the course work widget.","commonSituations":"Front-end passing the raw canvas course id instead of the prefixed \"course_{id}\" string; dropping the prefix during serialization; type coercion turning the value into an integer.","solutions":["Format the value as \"all\" or \"course_<numeric_id>\" (e.g. \"course_42\")","Ensure the value is a String, not an integer — stringify ids with \"course_#{id}\"","Verify the id portion contains digits only (no non-numeric characters)"],"exampleFix":"// before\nfilters: { \"selectedCourse\": 42 }\n// after\nfilters: { \"selectedCourse\": \"course_42\" }","handlingStrategy":"validation","validationCode":"if (filters.selectedCourse !== undefined) {\n  const v = filters.selectedCourse;\n  if (!(typeof v === \"string\" && (v === \"all\" || /^course_\\d+$/.test(v)))) {\n    throw new Error(\"selectedCourse must be 'all' or 'course_{id}'\");\n  }\n}","typeGuard":"const isValidSelectedCourse = (v) => typeof v === \"string\" && (v === \"all\" || /^course_\\d+$/.test(v));","tryCatchPattern":null,"preventionTips":["Always prefix course ids with \"course_\" at the point of serialization","Keep the value a string — never pass raw integers","Unit-test the formatter that builds selectedCourse values"],"tags":["graphql","validation","invalid-argument-format"],"backgroundTag":"invalid-argument-format","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"}