{"record":{"id":"37c78507fa3d15bb","repo":"payloadcms/payload","slug":"not-found-37c785","errorCode":null,"errorMessage":"Not Found","messagePattern":"Not Found","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"packages/payload/src/collections/operations/restoreVersion.ts","lineNumber":94,"sourceCode":"    }\n\n    // /////////////////////////////////////\n    // Retrieve original raw version\n    // /////////////////////////////////////\n\n    const { docs: versionDocs } = await req.payload.db.findVersions({\n      collection: collectionConfig.slug,\n      limit: 1,\n      locale: 'all',\n      pagination: false,\n      req,\n      where: { id: { equals: id } },\n    })\n\n    const [rawVersionToRestore] = versionDocs\n\n    if (!rawVersionToRestore) {\n      throw new NotFound(req.t)\n    }\n\n    const { parent: parentDocID, version: versionToRestoreWithLocales } = rawVersionToRestore\n\n    // /////////////////////////////////////\n    // Access\n    // /////////////////////////////////////\n\n    const accessResults = !overrideAccess\n      ? await executeAccess(\n          { id: parentDocID, slug: collectionConfig.slug, req },\n          collectionConfig.access.update,\n        )\n      : true\n    const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n    // /////////////////////////////////////\n    // Retrieve document","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/restoreVersion.ts#L76-L112","documentation":"Thrown as `new NotFound(req.t)` (HTTP 404) at packages/payload/src/collections/operations/restoreVersion.ts:94 when the database query for a version row with the given `id` returns zero docs. This means the version id does not exist in that collection's versions table (it may never have existed, was deleted, or belongs to another collection).","triggerScenarios":"Calling `payload.restoreVersion({ collection: 'pages', id: staleId })` with an id from a deleted version; passing a document id instead of a version id; the version was purged by a retention job; wrong collection (the version exists but under a different slug).","commonSituations":"Stale id cached in the UI after the version was deleted; copy-paste of a parent doc id where a version id was expected; cross-environment id leakage (dev id used against prod data).","solutions":["Confirm the id is a version id, not the parent document id.","Verify the version still exists with `payload.findVersionByID({ collection, id })` (or `disableErrors: true`) before calling restoreVersion.","Make sure you are targeting the correct collection slug."],"exampleFix":"// before\nawait payload.restoreVersion({ collection: 'pages', id }) // id may not exist\n\n// after\nconst existing = await payload.findVersionByID({ collection: 'pages', id, overrideAccess: true, disableErrors: true })\nif (!existing) {\n  return res.status(404).json({ error: 'Version not found' })\n}\nawait payload.restoreVersion({ collection: 'pages', id })","handlingStrategy":"validation","validationCode":"// Verify the version exists (without throwing) before restoring\nconst existing = await payload.findVersionByID({\n  collection: 'pages',\n  id: versionId,\n  overrideAccess: true,\n  disableErrors: true,\n})\nif (!existing) {\n  throw new Error(`Version '${versionId}' does not exist.`)\n}\nawait payload.restoreVersion({ collection: 'pages', id: versionId })","typeGuard":"const versionExists = async (payload: Payload, collection: CollectionSlug, id: string | number) => {\n  const v = await payload.findVersionByID({ collection, id, overrideAccess: true, disableErrors: true })\n  return Boolean(v)\n}","tryCatchPattern":"try {\n  await payload.restoreVersion({ collection: 'pages', id: versionId })\n} catch (err) {\n  if (err instanceof NotFound) {\n    // version id does not exist — tell the client 404\n  } else throw err\n}","preventionTips":["Confirm you are passing a version id, not a parent document id.","Refresh version lists in the UI after deletions to avoid stale ids.","Do not pass ids across environments (dev/prod)."],"tags":["local-api","restore-version","not-found","versions"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}