{"record":{"id":"6aafa3b374187dad","repo":"strapi/strapi","slug":"cannot-delete-a-draft-document","errorCode":null,"errorMessage":"Cannot delete a draft document","messagePattern":"Cannot delete a draft document","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/core/src/services/document-service/repository.ts","lineNumber":389,"sourceCode":"\n    const lookupQuery = await async.pipe(\n      validateParams,\n      omit('status'),\n      i18n.defaultLocale(contentType),\n      i18n.multiLocaleToLookup(contentType),\n      transformParamsToQuery(uid),\n      (query) => assoc('where', { ...query.where, documentId }, query)\n    )(params);\n\n    const selectionQuery = await async.pipe(\n      validateParams,\n      omit('status'),\n      pickSelectionParams,\n      transformParamsToQuery(uid)\n    )(params);\n\n    if (hasDraftAndPublish && params.status === 'draft') {\n      throw new Error('Cannot delete a draft document');\n    }\n\n    const entriesToDelete = await strapi.db.query(uid).findMany(lookupQuery);\n\n    const deletedEntries = await async.map(entriesToDelete, (entryToDelete: any) =>\n      entries.delete(entryToDelete.id, selectionQuery)\n    );\n\n    entriesToDelete.forEach(emitEvent('entry.delete'));\n\n    return { documentId, entries: deletedEntries };\n  }\n\n  async function create(opts = {} as any) {\n    const { documentId: _documentId, ...params } = opts;\n\n    const queryParams = await async.pipe(\n      validateParams,","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/strapi/strapi/blob/4a4101264d7098754df36e85fa629fd2f2349d8c/packages/core/core/src/services/document-service/repository.ts#L371-L407","documentation":"deleteDocument removes an entire document (all locales and the published+draft pair). It refuses to delete only the draft version, because that would orphan the published entry and break draftAndPublish integrity. When the content type has draftAndPublish enabled and params.status === 'draft', the call is rejected. To discard draft edits, use the discard-draft operation instead.","triggerScenarios":"Calling strapi.documents('api::article.article').delete({ documentId, status: 'draft' }) on a content type with draftAndPublish enabled.","commonSituations":"Confusing delete with unpublish/discard-draft; a UI button wired to delete the draft; automation that loops over statuses to delete selectively.","solutions":["Delete the whole document: strapi.documents(uid).delete({ documentId }) (omit status).","To remove only the published version, use status: 'published'.","To discard draft changes, use the discard-draft action (strapi.documents(uid).discardDraft(...)) or unpublish as appropriate.","Never pass status: 'draft' to deleteDocument on draftAndPublish content types."],"exampleFix":"// before (throws)\nawait strapi.documents('api::article.article').delete({\n  documentId,\n  status: 'draft',\n});\n\n// after — delete the whole document\nawait strapi.documents('api::article.article').delete({ documentId });\n\n// or discard only the draft changes\nawait strapi.documents('api::article.article').discardDraft({ documentId });","handlingStrategy":"validation","validationCode":"function deleteDocumentSafe(uid, opts) {\n  const ct = strapi.contentType(uid);\n  const hasDP = ct.options?.draftAndPublish === true;\n  if (hasDP && opts.status === 'draft') {\n    throw new Error('Use discardDraft to remove draft changes, or omit status to delete the document.');\n  }\n  return strapi.documents(uid).delete(opts);\n}","typeGuard":"const isDraftDeleteAttempt = (ct, opts) =>\n  ct.options?.draftAndPublish === true && opts?.status === 'draft';","tryCatchPattern":null,"preventionTips":["Map 'discard draft' UX to discardDraft, not delete.","Omit status on delete to remove the whole document.","Document the delete semantics for draftAndPublish types."],"tags":["document-service","delete","draft-and-publish","lifecycle"],"backgroundTag":null,"analyzedSha":"4a4101264d7098754df36e85fa629fd2f2349d8c","analyzedAt":"2026-08-12T12:47:50.760Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}