magento2
magento2 copied to clipboard
catalogsearch partial reindex is always running on product save in on schedule mode for products with negative qty
Preconditions and environment
- Magento 2.4.6-p2
- Magento indexers are in "on schedule" mode
Steps to reproduce
Requires technical specialist to do Elastic GET query
- In the admin set a negative qty to some product
- Save the product
- Do elastic query to check what info is there Something like curl -X GET "http://localhost:9200/magento2_product_1_v8/_doc/2043?_source=name"
- Update the product name
- Save the product
- Do elastic query to check if name has been changed immediately (not by schedule) curl -X GET "http://localhost:9200/magento2_product_1_v8/_doc/2043?_source=name"
P.S. Index name for queries above can be checked by http://localhost:9200/_cat/indices query Issue is reproducible only if with negative qty
Expected result
Save in the admin runs fast. No changes happen in Elastic. Changes are reflected after on schedule reindex process (in 1 minute by cron)
Actual result
Admin save takes more time. Changes in Elastic are applying immediately because reindex runs on save. Name has been changed.
Additional information
Force reindex happens on product save in vendor/magento/module-inventory-catalog-search/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/FulltextIndexUpdater.php::aroundExecuteList if product has negative qty because of the second parameter in reindexList. Calculations of $productsIdsToProcess should likely be adjusted
if (!empty($productsIdsToProcess)) { $this->fulltextIndexProcessor->reindexList($productsIdsToProcess, true); }
Main problem is that if you are using import scripts that update product data, for example, name, then it will always trigger catalogsearch reindex during the import if product has negative qty and OOS.
Release note
No response
Triage and priority
- [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- [X] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Hi @alexey-bo. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
-
@magento give me 2.4-develop instance
- upcoming 2.4.x release - For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this
- To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
vendor/magento/module-inventory-indexer/Model/GetProductsIdsToProcess.php has a bug
Diff part
foreach ($salableData as $stockId => $isSalable) {
- if (empty($after[$sku][$stockId])
+ if (!isset($after[$sku][$stockId])
|| $before[$sku][$stockId] !== $after[$sku][$stockId]
|| ($stockId === $this->defaultStockProvider->getId() && $forceDefaultStockProcessing)) {
Explanation vendor/magento/module-inventory-indexer/Model/GetProductsIdsToProcess.php::execute Try to pass 'before' => ['sku1' => [1 => false]], 'after' => ['sku1' => [1 => false]], Should return empty array, because there are no difference in items. In reality returns 1 item
Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
- [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
- [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
- [ ] 3. Add
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-develop
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! - [ ] 5. Add label
Issue: Confirmed
once verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @alexey-bo,
Thank you for the report and collaboration!
We tried to verify this issue on 2.4-develop, but in our case it was not reproducible.
Changing the product name with negative quantity did not trigger reindex and in the elasticsearch query the name remained the same.
Please take a look at the screenshot below:
Got the below result in the curl command:
{"_index":"magento2_product_3_v8","_type":"_doc","_id":"8","_version":7,"_seq_no":12,"_primary_term":1,"found":true,"_source":{"name":"test product 3"}}
Please let us know if we are missing anything.
Thank you.
@engcom-November Try to set these settings: Stores > Configuration > Catalog > Inventory > Display Out of Stock Products : yes Test product: edit > Advanced Inventory > Manage Stock is "yes"
After this do these steps:
- In the admin set "Out of Stock" for "Stock Status" for product with Manage Stock (product edit > Advanced Inventory > Manage Stock is "yes")
- Save the product
- Do elastic query to check what info is there, Something like curl -X GET "http://localhost:9200/magento2_product_1_v8/_doc/2043?_source=name"
- Update the product name
- Save the product
- Do elastic query to check if name has been changed immediately (not by schedule) curl -X GET "http://localhost:9200/magento2_product_1_v8/_doc/2043?_source=name"
Hello @alexey-bo,
Thank you for the response!
Made changes to the setting as you have mentioned, still the name remained the same in the index. We did not see any reindex after saving the product. This issue might have been resolved on the latest version. Please re-verify this on latest magento version, and let us know if the problem persist.
Thank you.
Hello @alexey-bo,
As there is no activity on this issue for a long time, we believe the issue has been resolved, hence closing this issue. Feel free to raise a new issue or reopen this if you need more assistance.
Thank you.