{"record":{"id":"5d8d77c9d57de0ba","repo":"payloadcms/payload","slug":"not-found-5d8d77","errorCode":null,"errorMessage":"Not Found","messagePattern":"Not Found","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"warning","filePath":"packages/payload/src/collections/operations/findByID.ts","lineNumber":189,"sourceCode":"      getSelectMode(select) === 'include'\n    ) {\n      dbSelect = { ...select, createdAt: true, updatedAt: true }\n    }\n\n    const findOneArgs: FindOneArgs = {\n      collection: collectionConfig.slug,\n      draftsEnabled: replaceWithVersion,\n      joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n      locale: locale!,\n      req: {\n        transactionID: req.transactionID,\n      } as PayloadRequest,\n      select: dbSelect,\n      where: fullWhere,\n    }\n\n    if (!findOneArgs.where?.and?.[0]?.id) {\n      throw new NotFound(t)\n    }\n\n    const docWithLocales = await req.payload.db.findOne(findOneArgs)\n\n    if (!docWithLocales && !args.data) {\n      if (!disableErrors) {\n        throw new NotFound(req.t)\n      }\n      return null!\n    }\n\n    let result: DataFromCollectionSlug<TSlug> =\n      (args.data as DataFromCollectionSlug<TSlug>) ?? docWithLocales!\n\n    // /////////////////////////////////////\n    // Add collection property for auth collections\n    // /////////////////////////////////////\n","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/findByID.ts#L171-L207","documentation":"In `findByIDOperation`, before the DB query it checks `findOneArgs.where?.and?.[0]?.id`; if absent it throws `NotFound(t)`. The combined where is `combineQueries({ id: { equals: id } }, accessResult)` whose first `and` entry is the id clause — so a missing/falsy `id` means the lookup has no id target.","triggerScenarios":"Calling `findByID({ collection, id })` (or `GET /api/{collection}/{id}`) with `id` undefined, null, or empty string, so the combined where clause's first `and` element lacks an `id`.","commonSituations":"A route param missing (`/api/posts/` with no id); an `id` variable undefined due to a typo; a programmatic call with `id: undefined`.","solutions":["Ensure a non-empty `id` is passed.","Validate the route param before calling `findByID`."],"exampleFix":"// before\nawait payload.findByID({ collection: 'posts', id: maybeId })\n// after\nif (!id) throw new Error('id required')\nawait payload.findByID({ collection: 'posts', id })","handlingStrategy":"validation","validationCode":"function requireId(id) {\n  if (id === undefined || id === null || id === '') {\n    throw new Error('id is required')\n  }\n}","typeGuard":"function hasId(id): id is string | number {\n  return id !== undefined && id !== null && id !== ''\n}","tryCatchPattern":null,"preventionTips":["Always validate id presence before `findByID`.","Avoid calling `findByID` with optional/undefined ids."],"tags":["read","not-found","validation","id"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}