{"record":{"id":"b210963f3da35650","repo":"medusajs/medusa","slug":"order-order-id-is-not-a-draft-order","errorCode":null,"errorMessage":"Order ${order.id} is not a draft order","messagePattern":"Order (.+?) is not a draft order","errorType":"exception","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/core/core-flows/src/draft-order/steps/validate-draft-order.ts","lineNumber":37,"sourceCode":" *\n * You can retrieve a draft order's details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),\n * or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).\n *\n * :::\n *\n * @example\n * const data = validateDraftOrderStep({\n *   order: {\n *     id: \"order_123\",\n *     // other order details...\n *   }\n * })\n */\nexport const validateDraftOrderStep = createStep(\n  \"validate-draft-order\",\n  async function ({ order }: ValidateDraftOrderStepInput) {\n    if (order.status !== OrderStatus.DRAFT && !order.is_draft_order) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `Order ${order.id} is not a draft order`\n      )\n    }\n  }\n)\n","sourceCodeStart":19,"sourceCodeEnd":44,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/core-flows/src/draft-order/steps/validate-draft-order.ts#L19-L44","documentation":"validateDraftOrderStep requires order.status === 'draft' or order.is_draft_order === true; otherwise the order cannot be manipulated through the draft-order workflows.","triggerScenarios":"Calling a draft-order workflow (confirm, add item, update, etc.) with an order id whose status is pending/completed/canceled and is_draft_order is false/null.","commonSituations":"Draft order was already confirmed and became a regular order; wrong order id passed (regular order mistaken for draft); legacy orders created before is_draft_order existed that were confirmed; client cached a draft id post-confirmation.","solutions":["Check order.status and order.is_draft_order before invoking the workflow","If the order was confirmed, use the regular order-edit workflows instead","Re-fetch the order to get its current status and correct the client state"],"exampleFix":"// before\nawait confirmDraftOrderWorkflow(container).run({ input: { id: orderId } }) // regular order\n\n// after\nconst order = await query.graph({ entity: \"order\", filters: { id: orderId }, fields: [\"status\", \"is_draft_order\"] })\nif (order.data[0].status === \"draft\" || order.data[0].is_draft_order) {\n  await confirmDraftOrderWorkflow(container).run({ input: { id: orderId } })\n}","handlingStrategy":"type-guard","validationCode":"if (order.status !== \"draft\" && !order.is_draft_order) throw new Error(\"Order is not a draft\")","typeGuard":"const isDraftOrder = (o: { status: string; is_draft_order?: boolean }) => o.status === \"draft\" || !!o.is_draft_order","tryCatchPattern":null,"preventionTips":["Check order.status/is_draft_order before any draft-order workflow call","Use order-edit workflows for confirmed orders"],"tags":["draft-order","order-status","validation"],"backgroundTag":"order-not-in-draft-state","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}