{"record":{"id":"bd64bf2214831d04","repo":"payloadcms/payload","slug":"not-found-bd64bf","errorCode":null,"errorMessage":"Not Found","messagePattern":"Not Found","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"packages/payload/src/duplicateDocument/index.ts","lineNumber":73,"sourceCode":"  let duplicatedFromDocWithLocales = await getLatestCollectionVersion({\n    id,\n    config: collectionConfig,\n    payload,\n    query: findOneArgs,\n    req,\n  })\n\n  if (selectedLocales && selectedLocales.length > 0 && duplicatedFromDocWithLocales) {\n    duplicatedFromDocWithLocales = filterDataToSelectedLocales({\n      configBlockReferences: payload.config.blocks,\n      docWithLocales: duplicatedFromDocWithLocales,\n      fields: collectionConfig.fields,\n      selectedLocales,\n    })\n  }\n\n  if (!duplicatedFromDocWithLocales && !hasWherePolicy) {\n    throw new NotFound(req.t)\n  }\n  if (!duplicatedFromDocWithLocales && hasWherePolicy) {\n    throw new Forbidden(req.t)\n  }\n\n  // remove the createdAt timestamp and rely on the db to set it\n  if ('createdAt' in duplicatedFromDocWithLocales) {\n    delete duplicatedFromDocWithLocales.createdAt\n  }\n  // remove the id and rely on the db to set it\n  if ('id' in duplicatedFromDocWithLocales) {\n    delete duplicatedFromDocWithLocales.id\n  }\n\n  duplicatedFromDocWithLocales = await beforeDuplicate({\n    id,\n    collection: collectionConfig,\n    context: req.context,","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/duplicateDocument/index.ts#L55-L91","documentation":"Thrown by `getDuplicateDocumentData` when the source document for duplication is not found AND the collection's read access is not a where-policy. Payload first applies read access, fetches the latest version, and if nothing comes back with a plain boolean access result it responds HTTP 404. This mirrors updateByID's not-found semantics for the duplicate operation.","triggerScenarios":"Calling `payload.duplicate({ id: '999' })` on a non-existent id; duplicating a hard-deleted document; the source id belongs to another collection.","commonSituations":"Stale 'duplicate' button in the UI pointing at a deleted doc; scripted duplication over a list where one id was removed; trashed source with `trash` not enabled in the lookup.","solutions":["Verify the source id exists (`payload.findByID`) before duplicating.","Surface a 'source not found' message to the user; do not retry.","If trash is enabled, ensure the source is not soft-trashed or operate with `trash: true`."],"exampleFix":"// before\nawait payload.duplicate({ collection: 'posts', id })\n// after\nconst src = await payload.findByID({ collection: 'posts', id }).catch(() => null)\nif (!src) throw new Error('source post not found')\nawait payload.duplicate({ collection: 'posts', id })","handlingStrategy":"validation","validationCode":"const src = await payload.findByID({ collection, id, depth: 0, req }).catch(() => null)\nif (!src) throw new Error(`Source ${id} not found; cannot duplicate`)\nawait payload.duplicate({ collection, id, req })","typeGuard":null,"tryCatchPattern":"try {\n  await payload.duplicate({ collection, id, req })\n} catch (err) {\n  if (err instanceof NotFound) return respond(404, 'Source document not found')\n  throw err\n}","preventionTips":["Existence-check the source id before duplicating.","Disable duplicate UI actions for ids known to be deleted.","Handle 404s gracefully in the client."],"tags":["duplicate","collections","not-found","local-api"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}