instructure/canvas-lms · error · GraphQL::ExecutionError
context not found
Error message
context not found
What it means
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.
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.
Example fix
// before
{contextType: "Course", contextId: 999999} // nonexistent
// after
{contextType: "Course", contextId: 123} // id verified via GET /api/v1/courses/123 Defensive patterns
Strategy: validation
Validate before calling
// pre-check via REST API
const exists = await fetch(`/api/v1/courses/${contextId}`).then(r => r.ok)
if (!exists) throw new Error('contextId does not reference an existing course') Try / catch
try { await mutation(input) } catch (e) { if (e.message === 'context not found') { /* refresh ids / verify shard */ } else throw e } Prevention
- Resolve fresh ids at call time instead of caching them
- Use Relay global ids for shard safety
- Confirm environment before using hard-coded ids
When it happens
Trigger: 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).
Common situations: 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.
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
- A course with that id does not exist
- ActiveRecord::RecordNotFound
- Allocation rule not found
- An assignment with that id does not exist
- Assignment not found
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/7e03862753445f03.
Report an issue: GitHub.
Appendix: source
Thrown at app/graphql/graphql_helpers/context_fetcher.rb:34
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module GraphQLHelpers::ContextFetcher
def context_fetcher(input, valid_context_types = [])
if valid_context_types.exclude?(input[:context_type])
raise GraphQL::ExecutionError, I18n.t("invalid context type")
end
context =
begin
context_type = Object.const_get(input[:context_type])
context_type.find_by(id: input[:context_id])
rescue
raise GraphQL::ExecutionError, I18n.t("invalid context type")
end
raise GraphQL::ExecutionError, I18n.t("context not found") if context.nil?
context
end
end
View on GitHub (pinned to 1c9f0bb801)