{"record":{"id":"62caf0225181f563","repo":"payloadcms/payload","slug":"not-found-62caf0","errorCode":null,"errorMessage":"Not Found","messagePattern":"Not Found","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"warning","filePath":"packages/payload/src/preferences/operations/delete.ts","lineNumber":37,"sourceCode":"\n  const where: Where = {\n    and: [\n      { key: { equals: key } },\n      { 'user.value': { equals: user.id } },\n      { 'user.relationTo': { equals: user.collection } },\n    ],\n  }\n\n  const result = await payload.db.deleteOne({\n    collection: preferencesCollectionSlug,\n    req,\n    where,\n  })\n\n  if (result) {\n    return result\n  }\n  throw new NotFound(req.t)\n}\n","sourceCodeStart":19,"sourceCodeEnd":39,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/preferences/operations/delete.ts#L19-L39","documentation":"Thrown by preferences `deleteOperation` after `payload.db.deleteOne` returns no result. The where clause filters by `key`, `user.value`, and `user.relationTo`; if zero rows match (key does not exist for this user), the DB returns nothing and the operation raises NotFound rather than silently no-op.","triggerScenarios":"Deleting a preference key that the current user never created, or that belongs to a different user; passing a wrong/typo key; deleting twice (second call finds nothing).","commonSituations":"UI sends a delete for a preference that was reset elsewhere; race condition where another session deleted it first; key mismatch (camelCase vs stored key).","solutions":["Check existence before deleting (findOne by key+user) and treat missing as success if idempotency is desired.","Wrap the delete in try/catch and ignore a 404 when the operation should be idempotent.","Verify the exact key string matches what was stored."],"exampleFix":"// before\nawait payload.delete({ collection: 'payload-preferences', id: key, req })\n\n// after\ntry {\n  await payload.delete({ collection: 'payload-preferences', id: key, req })\n} catch (err) {\n  if (err.statusCode !== 404) throw err\n}","handlingStrategy":"try-catch","validationCode":"import type { Where } from 'payload'\n\nasync function preferenceExists(payload, key: string, req): Promise<boolean> {\n  const where: Where = {\n    and: [\n      { key: { equals: key } },\n      { 'user.value': { equals: req.user.id } },\n      { 'user.relationTo': { equals: req.user.collection } },\n    ],\n  }\n  const { totalDocs } = await payload.count({ collection: 'payload-preferences', where, req })\n  return totalDocs > 0\n}","typeGuard":null,"tryCatchPattern":"import { APIError } from 'payload'\n\ntry {\n  await payload.delete({ collection: 'payload-preferences', id: key, req })\n} catch (err) {\n  if (err instanceof APIError && err.statusCode === 404) {\n    // already gone; treat as success (idempotent delete)\n  } else throw err\n}","preventionTips":["Treat preference delete as idempotent and swallow 404 in shared helpers.","Use exact key strings; centralize preference keys as constants.","Avoid double-deletes from concurrent sessions by deduping UI events."],"tags":["preferences","not-found","delete"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}