#32540 Throw error when updating stock when auto increment is exceed… #3309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)
Manual testing scenarios (*)
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');
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 (*)