Skip to content

Magento2 inventory_cleanup_reservations CRON job not working as expected for the large number of reservation records

The basic reason behind this is the MySQL group_concat_max_len value. If we have a large number of records in the reservation table then it fails to group concat the value.

Preconditions and environment
Magento 2.4.4 (enterprise) Actually for any version

Steps to reproduce

  • Three Order should be placed
  • The first two orders can have a single product but the third order should have more than one product.
  • Create a shipment for all the orders and observe the inventory_reservation table.
    enter image description here
  • To verify the issue with a small amount of data please modify the value of the groupConcatMaxLen variable from file vendor/magento/module-inventory-reservations/etc/di.xml. The default value is 32768 but for testing purposes, I have changed that to 3.
    enter image description here
  • Now to the setup:di: compile & flush the cache
  • Now manually execute the inventory_cleanup_reservations cron or wait for the cron to execute. Observe the inventory_reservation table.
    enter image description here
  • As per the above screenshot, the shipment_created reservation has not been deleted for the order #000000003. which should be deleted because compensation has happened for the order #000000003.
  • Now if you execute the inventory_cleanup_reservations cron as many as times you want it will not delete the records for order #000000003. It is because it didn’t find the compensation for the order placed
  • Now check the salable qty on the product grid. The salable qty is more than the source qty
    enter image description here

Expected result
The reservation should be deleted for all the compensated orders and the product salable qty should be corrected

Actual result
The reservation has not been deleted for all the compensated orders.