{"record":{"id":"15be0db526843380","repo":"instructure/canvas-lms","slug":"invalid-query-id","errorCode":null,"errorMessage":"Invalid query ID","messagePattern":"Invalid query ID","errorType":"exception","errorClass":"ArgumentError","httpStatus":400,"severity":"error","filePath":"app/controllers/page_views_controller.rb","lineNumber":916,"sourceCode":"  def pv5_fetch_result_service\n    PageViews::FetchResultService.new(pv5_config, requestor_user: @current_user)\n  end\n\n  def pv5_enqueue_batch_service\n    PageViews::EnqueueBatchQueryService.new(pv5_config, requestor_user: @current_user)\n  end\n\n  def pv5_poll_batch_service\n    PageViews::PollBatchQueryService.new(pv5_config, requestor_user: @current_user)\n  end\n\n  def pv5_fetch_batch_result_service\n    PageViews::FetchBatchResultService.new(pv5_config, requestor_user: @current_user)\n  end\n\n  def validate_query_id!\n    query_id = params[:query_id]\n    raise ArgumentError, \"Invalid query ID\" unless uuid?(query_id)\n  end\n\n  def uuid?(string)\n    !!(string =~ /\\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\Z/)\n  end\n\n  def require_pv5_configured!\n    render json: { error: t(\"Page views history is not available in this environment.\") }, status: :not_found unless PageViews::Configuration.configured?\n  end\nend\n","sourceCodeStart":898,"sourceCodeEnd":927,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/controllers/page_views_controller.rb#L898-L927","documentation":"PageViews (PV5) API helpers call validate_query_id! which raises ArgumentError 'Invalid query ID' when the supplied query_id is not a lowercase UUID matching the strict regex in uuid?. The query_id identifies a submitted async page-view query/batch whose results are fetched later.","triggerScenarios":"Calling poll_query, query_results, poll_batch_query, or batch_query_results endpoints with query_id missing, truncated, uppercase, wrapped in braces, or otherwise not a canonical 8-4-4-4-12 hex UUID.","commonSituations":"Copying the query id from logs with surrounding characters, truncating it in a shell variable, using the submission/job id instead of the query UUID, or storing it in a DB column that trimmed it.","solutions":["Pass the exact UUID string returned when the query/batch was created (from the JSON response)","Validate the format with the same regex before calling the endpoint","Remove any braces, whitespace, or 'urn:uuid:' prefixes and lowercase the string","If the id was lost, re-submit the query to obtain a fresh query_id"],"exampleFix":"// before\nawait pollQuery({ query_id: jobIdFromQueue }) // numeric job id\n// after\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;\nif (!UUID_RE.test(queryId)) throw new Error('bad query_id: ' + queryId);\nawait pollQuery({ query_id: queryId });","handlingStrategy":"validation","validationCode":"const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;\nconst isValidQueryId = (s) => typeof s === 'string' && UUID_RE.test(s);\nif (!isValidQueryId(queryId)) throw new TypeError('query_id must be a canonical lowercase UUID');","typeGuard":"const isQueryId = (v) => typeof v === 'string' && /^[0-9a-f]{8}(-[0-9a-f]{4}){4}[0-9a-f]{12}$/.test(v);\nif (!isQueryId(queryId)) failFast('bad query_id: ' + String(queryId));","tryCatchPattern":"try { return await pollQuery(queryId); } catch (e) { if (e instanceof ArgumentError && /Invalid query ID/.test(e.message)) { throw new Error(`malformed query_id '${queryId}' — use the UUID returned at query submission`); } throw e; }","preventionTips":["Persist the query UUID from the submit response verbatim","Trim/lowercase/strip braces from ids copied from logs before use","Never substitute job or batch numeric ids for the query UUID","Unit-test your id extraction from Canvas responses"],"tags":["uuid","validation","page-views","canvas-lms"],"backgroundTag":"invalid-identifier-format","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"}