medusajs/medusa · error · MedusaError

Order ${order.id} is not a draft order

Error message

Order ${order.id} is not a draft order

What it means

validateDraftOrderStep requires order.status === 'draft' or order.is_draft_order === true; otherwise the order cannot be manipulated through the draft-order workflows.

Source

Thrown at packages/core/core-flows/src/draft-order/steps/validate-draft-order.ts:37

 *
 * You can retrieve a draft order's details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
 * or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
 *
 * :::
 *
 * @example
 * const data = validateDraftOrderStep({
 *   order: {
 *     id: "order_123",
 *     // other order details...
 *   }
 * })
 */
export const validateDraftOrderStep = createStep(
  "validate-draft-order",
  async function ({ order }: ValidateDraftOrderStepInput) {
    if (order.status !== OrderStatus.DRAFT && !order.is_draft_order) {
      throw new MedusaError(
        MedusaError.Types.INVALID_DATA,
        `Order ${order.id} is not a draft order`
      )
    }
  }
)

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Check order.status and order.is_draft_order before invoking the workflow
  2. If the order was confirmed, use the regular order-edit workflows instead
  3. Re-fetch the order to get its current status and correct the client state

Example fix

// before
await confirmDraftOrderWorkflow(container).run({ input: { id: orderId } }) // regular order

// after
const order = await query.graph({ entity: "order", filters: { id: orderId }, fields: ["status", "is_draft_order"] })
if (order.data[0].status === "draft" || order.data[0].is_draft_order) {
  await confirmDraftOrderWorkflow(container).run({ input: { id: orderId } })
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (order.status !== "draft" && !order.is_draft_order) throw new Error("Order is not a draft")

Type guard

const isDraftOrder = (o: { status: string; is_draft_order?: boolean }) => o.status === "draft" || !!o.is_draft_order

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/b210963f3da35650. Report an issue: GitHub.