{"record":{"id":"77a6fed455fcf39b","repo":"Budibase/budibase","slug":"query-id-or-revision-is-missing","errorCode":null,"errorMessage":"Query ID or Revision is missing","messagePattern":"Query ID or Revision is missing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/builder/src/stores/builder/queries.ts","lineNumber":163,"sourceCode":"      ...state,\n      selectedQueryId: id,\n    }))\n  }\n\n  async preview(query: QueryPreview): Promise<PreviewQueryResponse> {\n    const result = await API.previewQuery(query)\n    // Assume all the fields are strings and create a basic schema from the\n    // unique fields returned by the server\n    const schema: Record<string, QuerySchema> = {}\n    for (let [field, metadata] of Object.entries(result.schema)) {\n      schema[field] = (metadata as QuerySchema) || { type: \"string\" }\n    }\n    return { ...result, schema, rows: result.rows || [] }\n  }\n\n  async delete(query: Query) {\n    if (!query._id || !query._rev) {\n      throw new Error(\"Query ID or Revision is missing\")\n    }\n    await API.deleteQuery(query._id, query._rev)\n    this.store.update(state => ({\n      ...state,\n      list: state.list.filter(existing => existing._id !== query._id),\n    }))\n    skipUnsavedPromptIds.delete(query._id)\n  }\n\n  async duplicate(query: Query) {\n    let list = get(this.store).list\n    const newQuery = { ...query }\n    const datasourceId = query.datasourceId\n\n    delete newQuery._id\n    delete newQuery._rev\n    newQuery.name = duplicateName(\n      query.name,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/builder/src/stores/builder/queries.ts#L145-L181","documentation":"The queries store's delete() method requires both the CouchDB document _id and _rev before it will call the delete API. If either is missing on the passed Query object it throws immediately, because a valid revision is needed for CouchDB to delete the document. This is a fail-fast guard to avoid sending a doomed request to the server.","triggerScenarios":"Calling store.queries.delete(query) with a query object that has no _id or no _rev — e.g. a newly constructed/in-memory query object, a query built from a template, or an object deserialized without the CouchDB metadata fields.","commonSituations":"Passing a draft query created before save; spreading a query into a new object and dropping internal fields; fetching query data from an endpoint that strips _rev; stale clients holding a partial query record.","solutions":["Ensure the query object comes from the store list or a full fetch so it includes _id and _rev","Check that the code constructing the Query object copies _id and _rev (don't pick only known fields)","If deleting a newly created query, save it first to obtain the CouchDB revision","Log the query object before delete to confirm both fields are present"],"exampleFix":"// before\nawait queries.delete({ name: q.name } as Query)\n// after\nconst full = get(queries).list.find(x => x._id === q._id)\nawait queries.delete(full)","handlingStrategy":"validation","validationCode":"const canDelete = (q: Query) => Boolean(q._id && q._rev)\nif (!canDelete(query)) throw new Error(\"Query requires _id and _rev before delete\")","typeGuard":"const isDeletableQuery = (q: Query): q is Query & { _id: string; _rev: string } =>\n  typeof q._id === \"string\" && typeof q._rev === \"string\"","tryCatchPattern":"try {\n  await queries.delete(query)\n} catch (e) {\n  if (e.message.includes(\"ID or Revision is missing\")) {\n    const full = get(queries).list.find(x => x._id === query._id)\n    if (full) await queries.delete(full)\n  } else throw e\n}","preventionTips":["Always source query objects from the store list or full API fetches","Avoid constructing Query objects manually from partial fields","Never spread-and-strip internal CouchDB fields (_id, _rev) before delete","Validate _id/_rev presence before invoking destructive operations"],"tags":["builder","couchdb","missing-id","validation"],"backgroundTag":"missing-document-id-or-rev","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}