{"record":{"id":"7e03862753445f03","repo":"instructure/canvas-lms","slug":"context-not-found","errorCode":null,"errorMessage":"context not found","messagePattern":"context not found","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/graphql_helpers/context_fetcher.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#\n\nmodule GraphQLHelpers::ContextFetcher\n  def context_fetcher(input, valid_context_types = [])\n    if valid_context_types.exclude?(input[:context_type])\n      raise GraphQL::ExecutionError, I18n.t(\"invalid context type\")\n    end\n\n    context =\n      begin\n        context_type = Object.const_get(input[:context_type])\n        context_type.find_by(id: input[:context_id])\n      rescue\n        raise GraphQL::ExecutionError, I18n.t(\"invalid context type\")\n      end\n    raise GraphQL::ExecutionError, I18n.t(\"context not found\") if context.nil?\n\n    context\n  end\nend\n","sourceCodeStart":16,"sourceCodeEnd":39,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/graphql_helpers/context_fetcher.rb#L16-L39","documentation":"If the context_type constantizes and queries fine but no record matches the given context_id, context_fetcher raises GraphQL::ExecutionError 'context not found' rather than returning a null node, so callers get an explicit error.","triggerScenarios":"Calling a mutation with contextType: 'Course' and a contextId that is not an existing course id (wrong shard, deleted course, or raw id encoded wrongly).","commonSituations":"Hard-coded ids from another environment; courses deleted between query authoring and execution; using a Canvas id without cross-shard prefix on a multi-shard install.","solutions":["Verify the context record exists and the id is correct (query it first).","Use a global/Relay id to get correct shard handling and encode it properly.","Confirm you are hitting the right environment/shard."],"exampleFix":"// before\n{contextType: \"Course\", contextId: 999999} // nonexistent\n// after\n{contextType: \"Course\", contextId: 123} // id verified via GET /api/v1/courses/123","handlingStrategy":"validation","validationCode":"// pre-check via REST API\nconst exists = await fetch(`/api/v1/courses/${contextId}`).then(r => r.ok)\nif (!exists) throw new Error('contextId does not reference an existing course')","typeGuard":null,"tryCatchPattern":"try { await mutation(input) } catch (e) { if (e.message === 'context not found') { /* refresh ids / verify shard */ } else throw e }","preventionTips":["Resolve fresh ids at call time instead of caching them","Use Relay global ids for shard safety","Confirm environment before using hard-coded ids"],"tags":["graphql","record-not-found"],"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"}