{"record":{"id":"7012d18ee6a6cb23","repo":"instructure/canvas-lms","slug":"assignment-not-found-course-type","errorCode":null,"errorMessage":"assignment not found","messagePattern":"assignment not found","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/types/course_type.rb","lineNumber":260,"sourceCode":"        Loaders::CourseOutcomeAlignmentStatsLoader.load(course) if course&.grants_right?(current_user, session, :manage_outcomes)\n      end\n    end\n\n    field :sections_connection, SectionType.connection_type, null: false do\n      argument :filter, CourseSectionsFilterInputType, required: false\n    end\n\n    def sections_connection(filter: {})\n      scope = course.active_course_sections\n\n      if filter[:assignment_id]\n        assignment = AbstractAssignment.assignment_scope_for_context(course).active.find(filter[:assignment_id])\n        scope = scope.where(id: assignment.sections_for_assigned_students) if assignment.only_visible_to_overrides?\n      end\n\n      scope.order(CourseSection.best_unicode_collation_key(\"name\"))\n    rescue ActiveRecord::RecordNotFound\n      raise GraphQL::ExecutionError, \"assignment not found\"\n    end\n\n    field :modules_connection, ModuleType.connection_type, null: true do\n      argument :filter,\n               Types::ModuleFilterInputType,\n               required: false,\n               description: \"Filter modules by various criteria\"\n    end\n    def modules_connection(filter: nil)\n      preload_course_permissions.then do\n        scope = course.modules_visible_to(current_user)\n\n        if filter\n          scope = apply_module_filters(scope, filter)\n        end\n\n        scope.order(:name)\n      end","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/types/course_type.rb#L242-L278","documentation":"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'.","triggerScenarios":"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).","commonSituations":"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.","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)"],"exampleFix":"// before\nsections(filter: { assignmentId: \"9999\" })  # not in this course\n// after\nconst id = assignment._id // id fetched from the same course\nsections(filter: { assignmentId: toGlobalId('Assignment', id) })","handlingStrategy":"try-catch","validationCode":"const assignment = assignmentsCache.find(a => a.id === filterAssignmentId && a.courseId === courseId)\nif (!assignment) throw new Error('assignment not found before querying sections')","typeGuard":"function isAssignmentInCourse(a, courseId) { return !!a && a.courseId === courseId && a.state === 'active' }","tryCatchPattern":"try { await query(SECTIONS_QUERY) } catch (e) { if (e.message === 'assignment not found') { clearFilterAndRefetch() } else throw e }","preventionTips":["Fetch assignment ids from the same course you query sections on","Use relay global IDs consistently","Refresh cached ids after assignment publish/delete events"],"tags":["graphql","not-found","assignments"],"backgroundTag":"record-not-found","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"}