inventory: Inventory reservation list inconsistencies command does not work

The command to list inconsistencies never completes in Magento 2.3.2. Database size: ~15GB Order Count: ~1137711 SKU Count: 7788

Preconditions (*)

  1. Migrated from Magento 1.9.4 to Magento 2.3.1
  2. Upgraded from Magento 2.3.1 to Magento 2.3.2
  3. Migration from 1.9 to 2.3 caused inventory inconsistencies as listed here - https://devdocs.magento.com/guides/v2.3/inventory/inventory-cli-reference.html

Steps to reproduce (*)

  1. Upgrade from 2.3.1 to 2.3.2
  2. Run the command to list inventory inconsistencies php -d memory_limit=-1 bin/magento inventory:reservation:list-inconsistencies -ir

Expected result (*)

  1. It should list the inconsistent inventories for effected SKUs

Actual result (*)

  1. The command keeps running forever and does not yield any result. It takes up all the server memory and still no result.
  2. In our case, it takes more than 20GB of memory and still not finished. here is screenshot from our server: image

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18

Most upvoted comments

@chrisbadley @moderncodes - thanks for input, this really saved my day. After making your modification, truncating order tables and then manually clearing inventory_reservation table, everything is working as it’s supposed to. Pfew 😉

@chrisbadley @ef1970 vendor/magento/module-inventory-reservation-cli/Model/SalableQuantityInconsistency/FilterManagedStockProducts.php

/**
     * Remove all reservations with incomplete state
     *
     * @param SalableQuantityInconsistency[] $inconsistencies
     * @return SalableQuantityInconsistency[]
     * @throws LocalizedException
     * @throws SkuIsNotAssignedToStockException
     */
public function execute(array $inconsistencies): array
    {
        foreach ($inconsistencies as $inconsistency) {
            $filteredItems = [];
            foreach ($inconsistency->getItems() as $sku => $qty) {
                if (false === $this->isProductAssignedToStock->execute((string)$sku, $inconsistency->getStockId())) {
                    continue;
                }

                $stockConfiguration = $this->getStockItemConfiguration->execute((string)$sku, $inconsistency->getStockId());
                if ($stockConfiguration->isManageStock()) {
                    $filteredItems[$sku] = $qty;
                }
            }
            $inconsistency->setItems($filteredItems);
        }

        return $inconsistencies;
    }

should fix it temporary, until someone fixes it in prod

Doesn’t seem that there’s an internal ticket for this issue.

We ran into this when we had products with all numeric SKUs and this error cropped up. Seems that for some reason all numeric SKUs are being interpreted as an integer at some point. Casting them to a string when calling the execute function resolves this particular issue.

I applied the same changes that @moderncodes posted here and it started working. It’s not a permanent fix, but it got me past where I needed to be.