{"record":{"id":"18a645c6601b1a87","repo":"payloadcms/payload","slug":"not-found-18a645","errorCode":null,"errorMessage":"Not Found","messagePattern":"Not Found","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"warning","filePath":"packages/payload/src/collections/operations/findVersionByID.ts","lineNumber":126,"sourceCode":"      versions: true,\n    })\n\n    const versionsQuery = await payload.db.findVersions<TData>({\n      collection: collectionConfig.slug,\n      limit: 1,\n      locale: locale!,\n      pagination: false,\n      req,\n      select,\n      where: fullWhere,\n    })\n\n    let result = versionsQuery.docs[0]!\n\n    if (!result) {\n      if (!disableErrors) {\n        if (!hasWhereAccess) {\n          throw new NotFound(req.t)\n        }\n        if (hasWhereAccess) {\n          throw new Forbidden(req.t)\n        }\n      }\n\n      return null!\n    }\n\n    if (!result.version) {\n      // Fallback if not selected\n      ;(result as any).version = {}\n    }\n\n    // /////////////////////////////////////\n    // beforeRead - Collection\n    // /////////////////////////////////////\n","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/findVersionByID.ts#L108-L144","documentation":"In `findVersionByIDOperation`, if the versions query returns no document and there is no where-access constraint, it throws `NotFound`. The version ID does not exist or was purged.","triggerScenarios":"`findVersionByID` for a version ID that does not exist, was deleted, or was auto-pruned by `versions.maxKept`.","commonSituations":"Stale version reference; version auto-pruned by a `maxKept` limit; version deleted via cleanup.","solutions":["Verify the version ID.","Handle 404 in the route, or pass `disableErrors: true` to get `null`."],"exampleFix":"// before\nconst v = await payload.findVersionByID({ collection: 'posts', id })\n// after\nconst v = await payload.findVersionByID({ collection: 'posts', id, disableErrors: true })\nif (!v) return notFound()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isNotFound(e): boolean {\n  return e?.statusCode === 404 || e?.name === 'NotFound'\n}","tryCatchPattern":"try {\n  return await payload.findVersionByID({ collection, id })\n} catch (e) {\n  if (isNotFound(e)) return null\n  throw e\n}","preventionTips":["Use `disableErrors: true` for optional version lookups.","Handle 404 on version routes gracefully."],"tags":["versions","not-found"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}