{"record":{"id":"2fbafa07f68e8b60","repo":"payloadcms/payload","slug":"not-found-2fbafa","errorCode":null,"errorMessage":"Not Found","messagePattern":"Not Found","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"packages/payload/src/globals/operations/findVersionByID.ts","lineNumber":90,"sourceCode":"      }),\n      versions: true,\n    })\n\n    const findGlobalVersionsArgs: FindGlobalVersionsArgs = {\n      global: globalConfig.slug,\n      limit: 1,\n      locale: locale!,\n      req,\n      select,\n      where: combineQueries({ id: { equals: id } }, accessResults),\n    }\n\n    // /////////////////////////////////////\n    // Find by ID\n    // /////////////////////////////////////\n\n    if (!findGlobalVersionsArgs.where?.and?.[0]?.id) {\n      throw new NotFound(req.t)\n    }\n\n    const { docs: results } = await payload.db.findGlobalVersions(findGlobalVersionsArgs)\n    if (!results || results?.length === 0) {\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    // Clone the result - it may have come back memoized\n    let result: any = deepCopyObjectSimple(results[0])","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/globals/operations/findVersionByID.ts#L72-L108","documentation":"Two `NotFound` throw sites in `findVersionByID`: (1) the combined `where` clause has no leading `id` filter (`where.and[0].id` missing), meaning the requested version id was dropped/malformed before the DB query; (2) the DB query returned no version rows and there is no where-access policy (with where-access it becomes `Forbidden`). Net effect: the requested global version does not exist or cannot be resolved for the caller.","triggerScenarios":"Calling `payload.findGlobalVersionByID` (or `GET /api/globals/<slug>/versions/<id>`) with an id that doesn't exist; passing a malformed/non-string id that gets stripped from the where clause; the version was deleted; the caller has where-access that excludes this version (then Forbidden).","commonSituations":"Stale version id stored in a client after the version was pruned; copy-pasting a URL with a truncated id; version truncation/limits deleting older versions; wrong global slug paired with a version id from another global.","solutions":["Confirm the version id exists via `findGlobalVersions` before requesting it.","Validate the id is a well-formed string/number before the call so it survives into the where clause.","Handle the 404 in the client and surface a 'version not found' state.","If versions are draft-only, ensure drafts/versions are enabled on the global."],"exampleFix":"// before (unknown id, throws NotFound)\nawait payload.findGlobalVersionByID({ slug: 'settings', id: someStaleId, req })\n// after (verify then fetch)\nconst { docs } = await payload.findGlobalVersions({ slug: 'settings', where: { id: { equals: someStaleId } }, req })\nif (!docs.length) return null\nawait payload.findGlobalVersionByID({ slug: 'settings', id: someStaleId, req })","handlingStrategy":"try-catch","validationCode":"// pre-check: confirm the version exists for the caller before fetching by id\nasync function versionExists(slug, id, req) {\n  const { totalDocs } = await payload.countGlobalVersions({\n    slug, where: { id: { equals: id } }, req,\n  })\n  return totalDocs > 0\n}\nif (!await versionExists('settings', id, req)) return null","typeGuard":"function isNotFoundOrForbidden(err: any): boolean {\n  return err?.name === 'NotFound' || err?.name === 'Forbidden' || err?.statusCode === 404 || err?.statusCode === 403\n}","tryCatchPattern":"try {\n  const v = await payload.findGlobalVersionByID({ slug: 'settings', id, req })\n  return v\n} catch (err) {\n  if (err?.name === 'NotFound' || err?.statusCode === 404) {\n    // version missing or caller cannot resolve it — handle as 'not found'\n    return null\n  }\n  if (err?.name === 'Forbidden' || err?.statusCode === 403) {\n    // where-access excluded this version\n    return null\n  }\n  throw err\n}","preventionTips":["Validate the version id shape before calling so it survives into the where clause.","Use `findGlobalVersions` for user-facing version lists; fetch by id only from trusted references.","Handle both 404 and 403 when versions are subject to where-access policies."],"tags":["global","versions","not-found","runtime","api"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}