Repository navigation
Feature: Handle inventory reservations in deleteProductsWorkflow — admin product deletion dead-ends when reservations exist #17805
dishanagalawatta
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Originally opened as issue #17799 — closed by the triage bot with a pointer here.
Context
deleteProductsWorkflow(the flow behindDELETE /admin/products/:id) currently dead-ends whenever any linked inventory item still has reservations. This is a dead-end in a universal flow: the Inventory Module is enabled by default, and any merchant who decommissions a product that has ever been ordered (completed orders keep reservations until fulfillment cleanup, and soft-deleted/cancelled test orders keep them indefinitely) cannot delete the product through the admin or the API.Current behavior
deleteProductsWorkflow(packages/core/core-flows/src/product/workflows/delete-products.ts) computes the inventory items to delete — an item is only removed when every variant linked to it is being deleted — then delegates todeleteInventoryItemWorkflow.validateInventoryDeleteStep(packages/core/core-flows/src/inventory/steps/delete-inventory-items.ts) throws:productsDeletedhook fires after the deletion steps, so a customization cannot cancel the reservations beforehand: the framework's intended extension point arrives too late to release linked resources.Why this hurts
DELETE /admin/products/:idis the standard cleanup path and it is unusable for products with any reservation history.Proposed solution (two options, in order of preference)
Option A — built-in handling in the core workflow: before delegating to
deleteInventoryItemWorkflow, cancel (soft-delete) the reservations held on exactly the inventory items the deletion will remove, with a restore-compensation on failure. ExposecancelledReservationIdsin the workflow response for observability. Reservation cancel/restore APIs already exist on the Inventory Module (softDeleteReservationItems/restoreReservationItems).Option B — framework-level minimum: fire a
beforeProductsDeletedhook before the deletion transaction (in addition to the existing post-deleteproductsDeletedhook), so customizations can release linked resources with access to the full query result (variants → inventory → reservations) instead of re-running the same query themselves.Reference implementation (running in production on Medusa 2.22.6)
We built
deleteProductsWithReservationsWorkflowas a wrapper around the core workflow:The wrapper is empty-safe, mirrors the core variant/inventory selection rule verbatim, restores reservations if the product deletion fails, and returns the cancelled reservation ids. It is covered by unit and integration tests. We're happy to open a PR implementing Option A (or B) in
core-flowsif the maintainers are receptive.Related
All reactions