{"record":{"id":"b3b9b758dfbc0539","repo":"instructure/canvas-lms","slug":"set-type-is-required-but-was-not-provided","errorCode":null,"errorMessage":"set_type is required, but was not provided","messagePattern":"set_type is required, but was not provided","errorType":"validation","errorClass":"Checkpoints::SetTypeRequiredError","httpStatus":null,"severity":"error","filePath":"app/services/checkpoints/date_override_common_service.rb","lineNumber":34,"sourceCode":"#\n# You should have received a copy of the GNU Affero General Public License along\n# with this program. If not, see <http://www.gnu.org/licenses/>.\n\nclass Checkpoints::DateOverrideCommonService < ApplicationService\n  def initialize(checkpoint:, overrides:)\n    super()\n    @checkpoint = checkpoint\n    @overrides = overrides\n  end\n\n  def call\n    @overrides.each do |override|\n      set_type = override.fetch(:set_type, nil)\n\n      # If set_type is nil and override has an id, fetch the set_type from the checkpoint\n      set_type = @checkpoint.assignment_overrides.find(override[:id]).set_type if set_type.nil? && override[:id]\n\n      raise Checkpoints::SetTypeRequiredError, \"set_type is required, but was not provided\" if set_type.nil?\n\n      service = services.fetch(set_type) { |key| raise Checkpoints::SetTypeNotSupportedError, \"set_type of '#{key}' not supported. Supported types: #{services.keys}\" }\n      service.call(checkpoint: @checkpoint, override:)\n    end\n  end\n\n  private\n\n  def services\n    {}\n  end\nend\n","sourceCodeStart":16,"sourceCodeEnd":47,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/checkpoints/date_override_common_service.rb#L16-L47","documentation":"Checkpoints::DateOverrideCommonService#call iterates @overrides and determines each override's set_type (e.g. CourseSection, ADHOC, Group). It reads set_type from the override hash, or looks it up from the existing AssignmentOverride when an :id is present; if neither source yields a set_type it raises SetTypeRequiredError. set_type is mandatory to select the right downstream service (services.fetch(set_type)).","triggerScenarios":"Calling call(checkpoint:, overrides:[...]) where an override hash has no :set_type and no :id, or has an :id that does not belong to @checkpoint.assignment_overrides (find raises) is different — this error fires specifically when set_type stays nil after both lookups, e.g. override: {} or override: {id: nil}.","commonSituations":"API consumers posting date overrides for discussion checkpoints without the set_type field; clients updating an existing override but passing the id under a different key so the lookup misses; hand-built hashes in specs/console omitting set_type.","solutions":["Include set_type: 'ADHOC'|'CourseSection'|'Group' (matching AssignmentOverride.set_type values) in each override hash.","If updating an existing override, pass its correct :id so the service can read set_type from the DB.","Validate the overrides payload in the controller before invoking the service."],"exampleFix":"// before\noverrides: [{ due_at: date }]\n// after\noverrides: [{ due_at: date, set_type: 'ADHOC' }]","handlingStrategy":"validation","validationCode":"overrides.each do |o|\n  raise ArgumentError, 'set_type or id required' if o[:set_type].blank? && o[:id].blank?\nend","typeGuard":"def set_type_resolvable?(override)\n  !override[:set_type].nil? || !override[:id].nil?\nend","tryCatchPattern":"begin\n  Checkpoints::DateOverrideCommonService.call(checkpoint:, overrides:)\nrescue Checkpoints::SetTypeRequiredError => e\n  render json: { error: e.message }, status: :bad_request\nend","preventionTips":["Always include set_type in override payloads, even when passing an id","Symbolize JSON param keys before building override hashes","Add a controller-side presence validation for set_type/id"],"tags":["ruby","canvas","validation","override-dates"],"backgroundTag":"missing-required-argument","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"}