instructure/canvas-lms · error · ActiveRecord::RecordNotFound
Cannot find # for ID: #
Error message
Cannot find #{params[:context_type] || "Context"} for ID: #{params[:context_id]} What it means
process_user_observer in lib/sis/user_observer_importer.rb raises this ImportError when the observer_id argument passed in is blank (nil, empty, or whitespace). An observer-less user_observer row cannot be resolved to a pseudonym via `@root_account.pseudonyms.active.find_by(sis_user_id: observer_id)`, so the import aborts that row. It is a required-argument guard executed before any database lookup.
Solutions
- Fix the source data so every user_observer row has a non-blank observer_id (the observer's SIS ID).
- Skip or fix blank rows in the pre-import pipeline instead of feeding them to the importer.
- If observer_id is legitimately unknown, remove the row rather than passing an empty string.
Example fix
// before (CSV row) user_id,observer_id STU001, // after user_id,observer_id STU001,OBS009
Defensive patterns
Strategy: validation
Validate before calling
raise 'observer_id required' if observer_id.nil? || observer_id.to_s.strip.empty?
Type guard
def blank?(v) = v.nil? || v.to_s.strip.empty?
Try / catch
begin
importer.process_user_observer(obs_id, stu_id, status)
rescue SIS::Import::ImportError => e
logger.warn("skipped row: #{e.message}")
end Prevention
- Validate required CSV columns before starting the SIS import.
- Trim and sanitize all identifier fields in pre-processing.
- Fail fast on blank required cells instead of passing rows through.
When it happens
Trigger: Calling SIS::UserObserverImporter#process_user_observer with observer_id nil/empty — e.g. a CSV users_observers row missing the observer_id column, or programmatic callers passing an empty string for observer_id while student_id is set.
Common situations: Malformed SIS CSV exports where the observer_id header exists but cells are empty; an integration script that skips optional-looking columns; template files where the observer column was accidentally left blank for some rows.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Context is required, but none found
- Context must be of type '#
- No account found for context
- A user did not pass validation
- An email did not pass validation
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/1724ce59cdac6801.
Report an issue: GitHub.
Appendix: source
Thrown at app/controllers/application_controller.rb:1455
flash[:warning] = flash_message
redirect_back_or_to root_url
end
end
set_no_cache_headers
end
# To be used as a before_action, requires controller or controller actions
# to have their urls scoped to a context in order to be valid.
# So /courses/5/assignments or groups/1/assignments would be valid, but
# not /assignments
def require_context(user_scope: nil)
get_context(user_scope:)
unless @context
if @context_is_current_user
store_location
redirect_to login_url
elsif params[:context_id]
raise ActiveRecord::RecordNotFound, "Cannot find #{params[:context_type] || "Context"} for ID: #{params[:context_id]}"
else
raise ActiveRecord::RecordNotFound, "Context is required, but none found"
end
end
!@context.nil?
end
def require_context_and_read_access
require_context && authorized_action(@context, @current_user, :read)
end
helper_method :clean_return_to
def require_account_context
require_context_type(Account)
end
def require_course_contextView on GitHub (pinned to 1c9f0bb801)