magento2: Inventory update of Configurable Product fails when database uses prefixes
Preconditions and environment
- Magento version: 2.4.6-p1
- Database encoding: utf8mb3_general_ci
- Setup Magento to use Database prefix.
- Example of Prefix: tst_
- Establish prefix in app/etc/env.php
- Rename all Tables of the Database with the prefix defined.
- Flush Cache and Redeploy Magento.
Steps to reproduce
After you setup Magento with Database prefix, create a configurable product A0 with 2 Simple Products inside A1 and A2. Then assign inventory source to the two simple products. Then try to set the inventory quantity for the Simple Products A1 and A2.
Expected result
The set quantity is saved and the quantity is recorded in the inventory Table.
Actual result
Error message appears (example) when trying to save:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'gtfnvnbmcy.cataloginventory_stock_status' doesn't exist, query was: UPDATE cataloginventory_stock_statusSETstock_status= ? WHERE (product_id = 745)
And the quantity is not saved.
Under this example of error, the product ID 745 is set for the Configurable product A0 and not for the Simple Products A1 and A2.
Additional information
I tried to modify the Inventory quantity in the Simple Products A1 and A2 who is part of Configurable Product A0 and also inside Configurable Product A0 directly. It gives the same error. It means that the Simple Product who is belonging to a Configurable Product uses the same saving protocol or script.
It seems that the SAVING action does not allow to assign the expected prefix to the database updating query. In the above example, it should point to table gtfnvnbmcy.tst_cataloginventory_stock_status instead of gtfnvnbmcy.cataloginventory_stock_status
Other information: It seems that the processor of the saving is located in this path: /public_html/vendor/magento/module-inventory-indexer/Model/ResourceModel/UpdateLegacyStockStatus.php This .php code calls the Table name cataloginventory_stock_status which is OK. But prefix is not added.
Release note
I can provide screen captures and testing results on demand. We Tested on Production server, Test Server and also on a fresh-new Magento installation: Same outcomes.
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.
- 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”.
About this issue
- Original URL
- State: open
- Created 9 months ago
- Comments: 16
Just a quick nudge that the issue BEHIND this is an inconsistency between variants of getTableName
in the context here
$this->resourceConnection->getTableName() adds prefix but $this->resourceConnection->getConnection()->getTableName() does NOT add prefix
This needs to be documented very clearly OR perhaps made more consistent