Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory reservation list inconsistencies command does not work #2522

Closed
arvind-curotec opened this issue Aug 29, 2019 · 18 comments
Closed

Comments

@arvind-curotec
Copy link

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
@chrisbadley
Copy link

In addition to this when I run the command inventory:reservation:list-inconsistencies, I receive the following fatal error, using Magento 2.3.2:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Inventory\Model\ResourceModel\IsProductAssignedToStock::execute() must be of the type string, integer given, called in /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory-reservation-cli/Model/SalableQuantityInconsistency/FilterManagedStockProducts.php on line 56 and defined in /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory/Model/ResourceModel/IsProductAssignedToStock.php:34
Stack trace: #0 /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory-reservation-cli/Model/SalableQuantityInconsistency/FilterManagedStockProducts.php(56): Magento\Inventory\Model\ResourceModel\IsProductAssignedToStock->execute(1060218, 1)
#1 /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory-reservation-cli/Model/GetSalableQuantityInconsistencies.php(105): Magento\InventoryReservationCli\Model\SalableQuantityInconsistency\FilterManagedStockProducts->execute(Array)
#2 /var/www/vhosts/XXXXXXX in /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory/Model/ResourceModel/IsProductAssignedToStock.php online 34

@albsa
Copy link

albsa commented Sep 6, 2019

Having this issue too, SKU is 7438257958967
Very annoying bug, also the salable quantity does not match with the stock.

The salable quantity is HIGHER than the stock, and backorders are DISABLED.
Also allowed quantity below 0 is 0.

@kernstmediarox
Copy link

Same here. ( string error and forever running )

@arvind-curotec
Copy link
Author

Finally I was able to run the command. It turned out that this command needs EXTREMELY large server resources. It will not success on small servers.
We increased server resources to 64GB RAM and then it worked. Even on that server it took more than an hour to complete.
This command is very inefficient and need serious optimization.

@moderncodes
Copy link

moderncodes commented Oct 10, 2019

In addition to this when I run the command inventory:reservation:list-inconsistencies, I receive the following fatal error, using Magento 2.3.2:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Inventory\Model\ResourceModel\IsProductAssignedToStock::execute() must be of the type string, integer given, called in /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory-reservation-cli/Model/SalableQuantityInconsistency/FilterManagedStockProducts.php on line 56 and defined in /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory/Model/ResourceModel/IsProductAssignedToStock.php:34
Stack trace: #0 /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory-reservation-cli/Model/SalableQuantityInconsistency/FilterManagedStockProducts.php(56): Magento\Inventory\Model\ResourceModel\IsProductAssignedToStock->execute(1060218, 1)
#1 /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory-reservation-cli/Model/GetSalableQuantityInconsistencies.php(105): Magento\InventoryReservationCli\Model\SalableQuantityInconsistency\FilterManagedStockProducts->execute(Array)
#2 /var/www/vhosts/XXXXXXX in /var/www/vhosts/XXXXXXX/htdocs/vendor/magento/module-inventory/Model/ResourceModel/IsProductAssignedToStock.php online 34

@chrisbadley It says is expecting your passed SKU 1060218 to be a type of string, integer given instead.

@ef1970
Copy link

ef1970 commented Oct 26, 2019

@chrisbadley - I'm having the exact same problem as you. Did you find a solution?

@chrisbadley
Copy link

@chrisbadley - I'm having the exact same problem as you. Did you find a solution?

Not yet, its on my agenda to look into soon, I am assuming that your SKU are totally numerical values also.

@chrisbadley
Copy link

chrisbadley commented Oct 26, 2019

@chrisbadley - I'm having the exact same problem as you. Did you find a solution?

I have a quick fix for you ef1970. In the file:

vendor/magento/module-inventory/Model/ResourceModel/IsProductAssignedToStock.php

Simply add $sku = "$sku"; at line 52 so the function becomes:

  public function execute(string $sku, int $stockId): bool
    {
        $connection = $this->resource->getConnection();
        $select = $connection->select()
            ->from(
                ['stock_source_link' => $this->resource->getTableName(StockSourceLink::TABLE_NAME_STOCK_SOURCE_LINK)]
            )->join(
                ['inventory_source_item' => $this->resource->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM)],
                'inventory_source_item.' . SourceItemInterface::SOURCE_CODE . '
                = stock_source_link.' . SourceItemInterface::SOURCE_CODE,
                []
            )->where(
                'stock_source_link.' . StockSourceLinkInterface::STOCK_ID . ' = ?',
                $stockId
            )->where(
                'inventory_source_item.' . SourceItemInterface::SKU . ' = ?',
                $sku
            );
        $sku = "$sku";
        return (bool)$connection->fetchOne($select);
    }

@kernstmediarox @albsa @ef1970

@moderncodes
Copy link

@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

@ef1970
Copy link

ef1970 commented Oct 26, 2019

@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 ;-)

@sudhanshu-bajaj
Copy link

Hi All,

Is this resolved on latest release or we need to follow temporary solution from @moderncodes ?

@judin
Copy link

judin commented May 4, 2020

Hi All,

Is this resolved on latest release or we need to follow temporary solution from @moderncodes ?

I'm here wondering exactly the same - although I'm running 2.3.4

@judin
Copy link

judin commented May 4, 2020

Hi All,
Is this resolved on latest release or we need to follow temporary solution from @moderncodes ?

I'm here wondering exactly the same - although I'm running 2.3.4

In reply @sudhanshu-bajaj I just updated my instance based on @chrisbadley and @moderncodes code changes above - and it resolves my issue (temporarily). Is this going to be in a release?

@konrad-konieczny
Copy link

konrad-konieczny commented Jun 16, 2020

looks like vendor/magento/module-inventory-reservation-cli/Model/SalableQuantityInconsistency/FilterManagedStockProducts.php still not fixed in new magento version, fatal error for numeric sku values

@AddyAhmed
Copy link

AddyAhmed commented Aug 25, 2020

The salable quantity is HIGHER than the stock, and backorders are DISABLED.
Also allowed quantity below 0 is 0.

@albsa Where you able to find the cause/resolve this issue? If so, do you mind sharing the solution please.

@HenKun
Copy link

HenKun commented Sep 15, 2020

Is there any open issue for this bug?

@bap14
Copy link

bap14 commented Sep 18, 2020

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.

@bap14
Copy link

bap14 commented Oct 5, 2020

According to Magento, this has been fixed in MSI 1.2 which is compatible with Magento 2.4. So if you're using Magento < 2.4 you will need to apply the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests