inventory
inventory copied to clipboard
#32540 Throw error when updating stock when auto increment is exceed…
Description (*)
In \Magento\Inventory\Model\ResourceModel\SourceItem\SaveMultiple the "INSERT ... ON DUPLICATE KEY UPDATE" statement is used to save records in inventory_source_item table. Since inventory_source_item table has more than one unique/primary key this statement is unsafe (see https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html at the bottom). In this particular case when the auto increment value is reached and new record is being inserted it will update the last record in the table instead of creating new one, no errors is thrown.
Fixed Issues (if relevant)
- Fixes magento/magento2#32540: API - No error when updating stock when auto increment is exceeded in inventory_source_item
Manual testing scenarios (*)
- Insert record to
inventory_source_item
table with max source_item_id 4294967295, e. g:INSERT INTO
inventory_source_item(
source_item_id,
source_code,
sku,
quantity,
status) VALUES (4294967295, 'default', 'test', '100.0000', '1');
- Create a new product via Magento Admin or API
Expected result: error is thrown.
Actual Result: no error is thrown, stock item is not saved. The item with source_item_id 4294967295 is updated instead.
Questions or comments
Contribution checklist (*)
- [ ] Pull request has a meaningful description of its purpose
- [ ] All commits are accompanied by meaningful commit messages
- [ ] All new or changed code is covered with unit/integration tests (if applicable)
- [ ] All automated tests passed successfully (all builds are green)
@magento run all tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.