cancel
Showing results for 
Search instead for 
Did you mean: 

Magento systematically deleting all products one by one, on its own?

Magento systematically deleting all products one by one, on its own?

We have a client with a new Magento 2.2.1 store with approx 35,000 products.

 

We are trying to identify the cause of a very odd problem.  For weeks now, they would notice at some point during the day, that several thousand products had disappeared from the store, and were disappearing at a rate of approx 1 per second.  When this behaviour is happening, I can run SELECT COUNT(*) FROM o4e_mage.catalog_product_entity every second, and watch the products disappearing.

 

Client has blamed suppliers of modules (MagePlaza, M2ePro) who have said it's impossible.  Another Magento 'expert' concluded that it was only possible if someone had hacked the site and was doing this from the backend.  We disagreed, and maintained that it felt like a Magento (or module) bug.

 

Today, I enabled the MySQL query log for all queries, and we identified the trigger for the problem, and can watch the problem happen in real time...

 

This problem is easily repeatable on the client's store, and they demonstrated it today, with shocking results...

 

To start, the client navigates to Catalog -> Products.  They select a bunch of products, eg. 10 from any page, and click Actions -> Delete.  If you're lucky, it will delete your selected products.

 

If you're unlucky, and 75% of the time this is what happens, the back end will become unresponsive and the user thinks it's crashed, and will restart their browser and carry on about their business.

 

In the background though, Magento is one by one deleting every trace of every single product from every product-related table.  Go away and make a coffee, and a few hundred products are gone.  Leave it a few hours and thousands have gone.  It seems to start from the last ID that you actually wanted to deleted, then increments the product ID by 1, and runs again, and again...

 

We've lost count of the times the client has had to restore her database and lose order history to fix this now, but at least we have linked it to the action of deleting a product, and have logged all the related queries.

 

Here is a snippet of the delete queries that we see on MySQL, note none of these products were selected for deletion:

 

 

15:31:34363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17554')
15:31:39363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17555')
15:31:43363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17592')
15:31:48363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17593')
15:31:52363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17594')
15:31:57363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17608')
15:32:01363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17644')
15:32:06363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17646')
15:32:10363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17807')
15:32:11363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17808')
15:32:11363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17809')
15:32:11363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17810')
15:32:12363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17811')
15:32:12363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17812')
15:32:12363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17813')
15:32:12363994QueryDELETE FROM `catalog_product_entity` WHERE (entity_id = '17814')

 

For anyone interested, the full query log for that MySQL thread is available here, it's 2.8MB uncompressed CSV file, with approx 7000 rows:

 

https://computercentric.co.uk/resources/query_log.zip

 

Note that the activity was stopped after a minute or so (by restarting MySQL or killing the thread) in order to stop every product disappearing.  Within the 7000 rows I can identify 50 products being deleted, along with all associated data on the same product ID.   Only 5 were selected for deletion.  (Aside from the obvious problem of deleting products we want to keep, why the flip does Magento need to run 7000 queries to delete 50 products??!  That's a question for another day...)

 

It is unbelievable to me (software developer hat on), that code can exist in either Magento core or a module, that can execute such a process without a failsafe in place.

 

Can anyone take on the challenge of identifying the cause of this bug?  If not, can anyone recommend where we should take this?  Disclaimer:  I am not a Magento expert, but I am pretty sure this ain't right.

 

Thanks in advance to anyone brave enough.

 

Ross

 

 

 

3 REPLIES

Re: Magento systematically deleting all products one by one, on its own?

@RossCC Very bad to hear this, hoping that you'll get a solution of this very soon. However, there are few things which I would like to include:

 

Possible ways to delete products are from the backend (Product grid) MySql (delete query or trigger), PHP script or CRON script.

 

Until you sure please stop access of admin (if shared with multiple users), second disabled all CRONs and analysis / compare Magento document root files with Vanilla Magento and your project files.  the last thing, to check is there any trigger set on MySQL.

 

Hope this helps, cheers!

 

P.S - Mostly, none of the extension merchants adds such scripts to delete products as per your behavior; but it might be subjective. 

 

-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Magento systematically deleting all products one by one, on its own?

Hi there - yes these queries are being individually executed by a script, presumably Magento core, they are not the results of a MySQL trigger.

 

All crons are disabled, and the problem only occurs when you attempt to delete a handful of products.

 

For anyone reading this may be related to this bug:

 

https://github.com/magento/magento2/pull/15985

Re: Magento systematically deleting all products one by one, on its own?

Further to above, it appears a fix is available for this in the form of a patch, as this has been identified as a critical issue.  Just trying to figure out how to implement this...