instructure/canvas-lms · error · GraphQL::ExecutionError
assignment not found
Error message
assignment not found
What it means
CourseType.sections_connection resolves an optional assignment filter by looking up the assignment through assignment_scope_for_context(...).active.find. If the id does not resolve to a visible/active assignment for the current course+user, ActiveRecord::RecordNotFound is rescued and re-raised as 'assignment not found'.
Solutions
- Verify the assignment id belongs to the same course and is active before filtering
- Use the correct relay global ID for the assignment
- Remove the assignment_id filter if you want all sections
- Confirm the user has visibility to the assignment (it may be only_visible_to_overrides)
Example fix
// before
sections(filter: { assignmentId: "9999" }) # not in this course
// after
const id = assignment._id // id fetched from the same course
sections(filter: { assignmentId: toGlobalId('Assignment', id) }) Defensive patterns
Strategy: try-catch
Validate before calling
const assignment = assignmentsCache.find(a => a.id === filterAssignmentId && a.courseId === courseId)
if (!assignment) throw new Error('assignment not found before querying sections') Type guard
function isAssignmentInCourse(a, courseId) { return !!a && a.courseId === courseId && a.state === 'active' } Try / catch
try { await query(SECTIONS_QUERY) } catch (e) { if (e.message === 'assignment not found') { clearFilterAndRefetch() } else throw e } Prevention
- Fetch assignment ids from the same course you query sections on
- Use relay global IDs consistently
- Refresh cached ids after assignment publish/delete events
When it happens
Trigger: course.sections(filter: { assignmentId: X }) where X is not an id of an active assignment scoped to that course for the requesting user (wrong course, deleted, unpublished, or only-visible-to-overrides assignment).
Common situations: Client caching an assignment id from a different course; assignment deleted or unpublished after the id was captured; ID/legacy-id mismatch when encoding relay global ids.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- not found
- Allocation rule not found
- Assignment group category id and discussion topic group…
- Assignment not found
- assignment not found: #
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/7012d18ee6a6cb23.
Report an issue: GitHub.
Appendix: source
Thrown at app/graphql/types/course_type.rb:260
Loaders::CourseOutcomeAlignmentStatsLoader.load(course) if course&.grants_right?(current_user, session, :manage_outcomes)
end
end
field :sections_connection, SectionType.connection_type, null: false do
argument :filter, CourseSectionsFilterInputType, required: false
end
def sections_connection(filter: {})
scope = course.active_course_sections
if filter[:assignment_id]
assignment = AbstractAssignment.assignment_scope_for_context(course).active.find(filter[:assignment_id])
scope = scope.where(id: assignment.sections_for_assigned_students) if assignment.only_visible_to_overrides?
end
scope.order(CourseSection.best_unicode_collation_key("name"))
rescue ActiveRecord::RecordNotFound
raise GraphQL::ExecutionError, "assignment not found"
end
field :modules_connection, ModuleType.connection_type, null: true do
argument :filter,
Types::ModuleFilterInputType,
required: false,
description: "Filter modules by various criteria"
end
def modules_connection(filter: nil)
preload_course_permissions.then do
scope = course.modules_visible_to(current_user)
if filter
scope = apply_module_filters(scope, filter)
end
scope.order(:name)
endView on GitHub (pinned to 1c9f0bb801)