instructure/canvas-lms · error
Sort by field '# ' is not supported
Error message
Sort by field '#{field}' is not supported What it means
AssignmentType#assignment_target_connection orders assignment overrides by a whitelisted set of fields (title, due_at, lock_at, unlock_at); any other order_by[:field] raises this error before being interpolated into SQL. It protects against arbitrary ORDER BY injection.
Solutions
- Use one of the supported field values: title, due_at, lock_at, unlock_at
- Normalize the client's sort keys to snake_case before sending
- Extend the whitelist in assignment_type.rb if a new sort field is legitimately needed (with proper column validation)
Example fix
// before
orderBy: { field: "dueAt", direction: "ascending" }
// after
orderBy: { field: "due_at", direction: "ascending" } Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_SORT_FIELDS = ['title', 'due_at', 'lock_at', 'unlock_at'];
if (orderBy?.field && !SUPPORTED_SORT_FIELDS.includes(orderBy.field)) {
throw new Error(`Sort field must be one of ${SUPPORTED_SORT_FIELDS.join(', ')}`);
} Type guard
function isSupportedSortField(f) {
return ['title', 'due_at', 'lock_at', 'unlock_at'].includes(f);
} Try / catch
try {
await fetchAssignmentOverrides(query, orderBy);
} catch (e) {
if (/Sort by field .* is not supported/.test(e.message)) {
showError('Unsupported sort field; use title, due_at, lock_at, or unlock_at.');
}
} Prevention
- Centralize the whitelist of sortable fields and import it in clients
- Convert camelCase GraphQL names to snake_case column names in one adapter layer
- Add tests asserting each supported sort value passes
- Never interpolate user-supplied ORDER BY columns without whitelist checks
When it happens
Trigger: A GraphQL query on assignment assignmentOverrides/connection with orderBy field set to something other than title, due_at, lock_at, or unlock_at (e.g. 'id', 'dueAt' camelCase, 'created_at').
Common situations: Clients sending camelCase GraphQL field names instead of the SQL-style column names the backend expects; UI added a new sort column before backend whitelist updated.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Assignment group category id and discussion topic group…
- assignment not found
- Assignments under moderation cannot be posted before grades…
- Error posting assignment grades
- Group category IDs do not match
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/c8ffa8295016c55b.
Report an issue: GitHub.
Appendix: source
Thrown at app/graphql/types/assignment_type.rb:931
end
end
end
end
field :assignment_target_connection, AssignmentOverrideType.connection_type, null: true do
argument :order_by, AssignmentTargetSortOrderInputType, required: false
end
def assignment_target_connection(order_by: nil)
load_association(:context).then do |context|
return unless context.grants_any_right?(current_user, *RoleOverride::GRANULAR_MANAGE_ASSIGNMENT_PERMISSIONS)
scope = assignment.all_assignment_overrides.active
if order_by.present?
field = order_by[:field]
direction = (order_by[:direction] == "descending") ? "DESC NULLS LAST" : "ASC"
raise "Sort by field '#{field}' is not supported" unless %w[title due_at lock_at unlock_at].include?(field)
scope = scope.order(Arel.sql("assignment_overrides.#{field} #{direction}"))
end
scope
end
end
field :anonymous_student_identities, [AnonymousStudentIdentityType], null: true
def anonymous_student_identities
return nil unless assignment.context.grants_right?(current_user, :manage_grades)
assignment.anonymous_student_identities.values
end
field :auto_grade_assignment_issues, Types::EligibilityIssueType, null: true, description: "Issues related to the assignment", deprecation_reason: "Use autoGradeEligibility instead"
def auto_grade_assignment_issues
load_association(:context).then do |course|View on GitHub (pinned to 1c9f0bb801)