instructure/canvas-lms · error · ArgumentError

Invalid query ID

Error message

Invalid query ID

What it means

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.

Solutions

  1. Pass the exact UUID string returned when the query/batch was created (from the JSON response)
  2. Validate the format with the same regex before calling the endpoint
  3. Remove any braces, whitespace, or 'urn:uuid:' prefixes and lowercase the string
  4. If the id was lost, re-submit the query to obtain a fresh query_id

Example fix

// before
await pollQuery({ query_id: jobIdFromQueue }) // numeric job id
// after
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
if (!UUID_RE.test(queryId)) throw new Error('bad query_id: ' + queryId);
await pollQuery({ query_id: queryId });
Defensive patterns

Strategy: validation

Validate before calling

const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
const isValidQueryId = (s) => typeof s === 'string' && UUID_RE.test(s);
if (!isValidQueryId(queryId)) throw new TypeError('query_id must be a canonical lowercase UUID');

Type guard

const isQueryId = (v) => typeof v === 'string' && /^[0-9a-f]{8}(-[0-9a-f]{4}){4}[0-9a-f]{12}$/.test(v);
if (!isQueryId(queryId)) failFast('bad query_id: ' + String(queryId));

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/15be0db526843380. Report an issue: GitHub.

Appendix: source

Thrown at app/controllers/page_views_controller.rb:916

  def pv5_fetch_result_service
    PageViews::FetchResultService.new(pv5_config, requestor_user: @current_user)
  end

  def pv5_enqueue_batch_service
    PageViews::EnqueueBatchQueryService.new(pv5_config, requestor_user: @current_user)
  end

  def pv5_poll_batch_service
    PageViews::PollBatchQueryService.new(pv5_config, requestor_user: @current_user)
  end

  def pv5_fetch_batch_result_service
    PageViews::FetchBatchResultService.new(pv5_config, requestor_user: @current_user)
  end

  def validate_query_id!
    query_id = params[:query_id]
    raise ArgumentError, "Invalid query ID" unless uuid?(query_id)
  end

  def uuid?(string)
    !!(string =~ /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\Z/)
  end

  def require_pv5_configured!
    render json: { error: t("Page views history is not available in this environment.") }, status: :not_found unless PageViews::Configuration.configured?
  end
end

View on GitHub (pinned to 1c9f0bb801)