instructure/canvas-lms · error · ActionController::BadRequest

Invalid submission_type for new assignment: #

Error message

Invalid submission_type for new assignment: #{submission_type[:type]}

What it means

Lti::LineItem creation supports only certain submission types when building the backing assignment. If a new assignment is requested with a submission_type whose :type is not one of the supported values (e.g. not 'external_tool' or 'online_upload' paths handled above), an ActionController::BadRequest is raised.

Solutions

  1. Send a supported submission_type :type (e.g. external_tool with external_tool_url) or omit submission_type for new assignments
  2. Attach the line item to an existing assignment instead of creating a new one when using unsupported submission types
  3. Rescue ActionController::BadRequest in the AGS controller and return a 400 with a clear message to the tool

Example fix

// before
{ "scoreMaximum": 10, "tag": "foo", "submission_type": { "type": "online_text_entry" } }
// after
{ "scoreMaximum": 10, "tag": "foo", "submission_type": { "type": "external_tool", "external_tool_url": "https://tool.example/launch" } }
Defensive patterns

Strategy: validation

Validate before calling

allowed = ["external_tool", "online_upload"]
raise ActionController::BadRequest unless allowed.include?(submission_type[:type])

Try / catch

begin
  Lti::LineItem.build_assignment(...)
rescue ActionController::BadRequest => e
  render json: { errors: e.message }, status: :bad_request
end

Prevention

When it happens

Trigger: POSTing an AGS line item (LTI 1.3 Assignment and Grade Services) whose tag attributes include a submission_type with an unsupported :type for a new assignment.

Common situations: Malformed LTI AGS requests from external tools; clients sending submission types like 'online_text_entry' or arbitrary strings where only external_tool/online_upload are accepted for new assignments; API clients building requests by hand.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/8ab32814d89c75f2. Report an issue: GitHub.

Appendix: source

Thrown at app/models/lti/line_item.rb:92

        context:,
        name: params[:label],
        points_possible: params[:score_maximum],
        submission_types: "none",
        due_at: params[:end_date_time],
        unlock_at: params[:start_date_time]
      }

      submission_type = params[AGS_EXT_SUBMISSION_TYPE]
      unless submission_type.nil?
        if Assignment::OFFLINE_SUBMISSION_TYPES.include?(submission_type[:type].to_sym)
          assignment_attr[:submission_types] = submission_type[:type]
          assignment_attr[:external_tool_tag_attributes] = {
            url: submission_type[:external_tool_url]
          }

          params = extract_extensions(params)
        else
          raise ActionController::BadRequest, "Invalid submission_type for new assignment: #{submission_type[:type]}"
        end
      end

      line_item = nil
      if assignment.blank?
        # Creating a new assignment of submission type external_tool creates a "default"
        # LineItem (and associated ResourceLink) which we can just modify & use
        assignment = Assignment.create!(assignment_attr)
        line_item = assignment.line_items.first
      end

      line_item ||= new(assignment:, root_account_id: assignment.root_account_id)
      attrs = params.to_h.merge(coupled: false).compact
      attrs[:client_id] = tool.global_developer_key_id if tool
      line_item.update!(attrs)
      line_item
    end
  end

View on GitHub (pinned to 1c9f0bb801)