inventory icon indicating copy to clipboard operation
inventory copied to clipboard

ACSD-67166 patch - incorrect logic when filtering products to load from legacy stock status cache

Open engcom-Hotel opened this issue 2 months ago • 3 comments

Creating this issue on behalf of @samjack28361, refer this issue https://github.com/magento/magento2/issues/40256

Preconditions and environment

  • Magento version 2.4.x

The official patch ACSD-67166 (https://experienceleague.adobe.com/en/docs/commerce-operations/tools/quality-patches-tool/patches-available-in-qpt/v1-1-70/acsd-67166) has the following change in the file Magento\InventoryCatalog\Model\LegacyStockStatusCache:

// Filter out product IDs that are already cached
$productIdsToLoad = array_filter($productIds, function ($productId) use ($scopeId) {
   return $this->legacyStockStatusStorage->get((int)$productId, $scopeId) !== null;

According to the PHP function definition of array_filter (https://www.php.net/manual/en/function.array-filter.php), this piece of code seems to be doing the opposite of what it is intending to do:

If the callback function returns true, the current value from array is returned into the result array.

This means $productIdsToLoad is going to be a list of product Ids that are already cached which is the opposite of what is desired (list of product IDs excluding those already cached). This means that $productIdsToLoad is always empty, and the legacyStockCache never gets preloaded. The callback function should be checking for null, not not null.

Steps to reproduce

  1. Set a breakpoint in the array_filter callback function.

$this->legacyStockStatusStorage->get() returns null if the product is not cached which means that $this->legacyStockStatusStorage->get((int)$productId, $scopeId) !== null; returns true when the product is cached.

Expected result

Uncached product ids are added to $productIdsToLoad which in turn are then loaded and added to the legacy stock status storage.

Actual result

Uncached product ids are not added to $productIdsToLoad which in turn are then loaded and added to the legacy stock status storage.

engcom-Hotel avatar Nov 11 '25 08:11 engcom-Hotel

Hi @engcom-Hotel. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information. Add a comment to assign the issue: @magento I am working on this


Join Magento Community Engineering Slack and ask your questions in #github channel.

m2-assistant[bot] avatar Nov 11 '25 08:11 m2-assistant[bot]

Hello @samjack28361,

Thank you for the report and collaboration!

We have tried to reproduce this issue in the latest development branch i.e. develop and the issue is reproducible for us.

Hence we are confirming this issue.

Thank you for bringing this issue to our attention. If you have a potential solution, we encourage you to submit a pull request. Your contributions significantly enhance Magento Open Source for everyone. Should you need any assistance, please don't hesitate to ask!

engcom-Hotel avatar Nov 11 '25 08:11 engcom-Hotel

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-16015 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Nov 11 '25 08:11 github-jira-sync-bot