{"record":{"id":"81905bccb2c8f622","repo":"instructure/canvas-lms","slug":"context-is-required-but-none-found","errorCode":null,"errorMessage":"Context is required, but none found","messagePattern":"Context is required, but none found","errorType":"exception","errorClass":"ActiveRecord::RecordNotFound","httpStatus":404,"severity":"error","filePath":"app/controllers/application_controller.rb","lineNumber":1457,"sourceCode":"      end\n    end\n    set_no_cache_headers\n  end\n\n  # To be used as a before_action, requires controller or controller actions\n  # to have their urls scoped to a context in order to be valid.\n  # So /courses/5/assignments or groups/1/assignments would be valid, but\n  # not /assignments\n  def require_context(user_scope: nil)\n    get_context(user_scope:)\n    unless @context\n      if @context_is_current_user\n        store_location\n        redirect_to login_url\n      elsif params[:context_id]\n        raise ActiveRecord::RecordNotFound, \"Cannot find #{params[:context_type] || \"Context\"} for ID: #{params[:context_id]}\"\n      else\n        raise ActiveRecord::RecordNotFound, \"Context is required, but none found\"\n      end\n    end\n    !@context.nil?\n  end\n\n  def require_context_and_read_access\n    require_context && authorized_action(@context, @current_user, :read)\n  end\n\n  helper_method :clean_return_to\n\n  def require_account_context\n    require_context_type(Account)\n  end\n\n  def require_course_context\n    require_context_type(Course)\n  end","sourceCodeStart":1439,"sourceCodeEnd":1475,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/controllers/application_controller.rb#L1439-L1475","documentation":"process_user_observer raises this ImportError when the student_id argument (the user being observed) is blank. Without a student SIS ID the importer cannot look up the target user's pseudonym, so the row is rejected before any DB access. This is the counterpart required-argument guard to the observer_id check on the previous line.","triggerScenarios":"Calling process_user_observer(observer_id, nil, status) or with an empty-string student_id — typically a users_observers CSV row with a populated observer_id but an empty user_id cell.","commonSituations":"CSV where user_id column was truncated or misnamed during export; scripts that pass nil because the student SIS ID was not yet provisioned; column-order assumptions after a template change.","solutions":["Supply the student's non-blank SIS user_id in the row or call.","Validate required columns (observer_id, user_id, status) before running the SIS import.","Drop rows missing user_id and re-run the batch for corrected data."],"exampleFix":"// before\nprocess_user_observer('OBS009', nil, 'active')\n\n// after\nprocess_user_observer('OBS009', 'STU001', 'active')","handlingStrategy":"validation","validationCode":"raise 'student_id required' if student_id.nil? || student_id.to_s.strip.empty?","typeGuard":"def blank?(v) = v.nil? || v.to_s.strip.empty?","tryCatchPattern":"begin\n  importer.process_user_observer(obs_id, stu_id, status)\nrescue SIS::Import::ImportError => e\n  logger.warn(\"skipped row: #{e.message}\")\nend","preventionTips":["Check users_observers CSV rows for both observer_id and user_id before import.","Ensure column headers map correctly (user_id = student being observed).","Reject rows missing either identifier during ETL validation."],"tags":["sis-import","ruby","missing-argument","user-observer"],"backgroundTag":"missing-required-argument","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"}