Open Berdir opened 5 years ago
I did run into this in an integration test for a module I'm creating.
I added a workaround there: https://github.com/swisspost-yellowcube/magento2-yellowcube/commit/78ad1b2795deaaa44ddc27fcf3621861c4c1aafd#diff-fbc227e53b22951fbb542a93bfd927aeR278, without that, the test fails.
It seems that saving a shipment with changes can result in repeated stock deduction.
I assume that this should prevent that:
I think this might only happen if a shipment is saved again in the same process, because \Magento\Sales\Model\Order\ShipmentRepository::save() puts the saved entity into the repository, but that means that \Magento\Framework\EntityManager\Observer\AfterEntityLoad::execute() doesn't run on it when loading it again, then it has no original data.
Preconditions (*)
Steps to reproduce (*)
Create a shipment, save it, then load it again from the repository, make a change and save it again.
Expected result (*)
Stock did not change.
Actual result (*)
Stock is deducted again.
Maybe there is a more reliable way to check that an entity wasn't new?