Magento 2 – Asymmetric transaction rollback error
Sometimes if you save a product you may get an “Asymmetric transaction rollback error“. I had this problem multiple time for my product importer. In this article I show you some basic understanding about this error and how to fix it.
Magento 2 – Asymmetric transaction rollback error
Sometimes Magento 2 seems to be very buggy. The “Asymmetric transaction rollback” is one of its major mysteries. This specific error message shows us, that Magento 2 uses transactions to write data into database. Transactions are helpful to avoid making data invalid. There are only two options:
- transaction successful
it is garanteed, that all SQL operations within this transaction are computed without a problem. So you data are valid. - transaction error
something happened during executing your transaction. Transaction systems provides a function called rollback, where your data are restored to a snapshot before starting a transaction.
As far as I know the message is only shown after you try to save a product.
How to solve this problem
For my import script I learned the following: my source is not the cause of the problem. During importing thousands of products, the error sometimes appears. It also appears on random products, so there was absolutely nothing points to a specific code block. The problem can also occur in your backend.
To solve this product simply run a reindex from command line:
1 | php bin/magento indexer:reindex |
If that does not fix it, please clean also all cached data:
1 2 3 | rm -rf var/cache/* rm -rf var/page_cache/* rm -rf var/generation/* |
What does asymmetric means?
I have never heard about the word asymmetric in combination with database rollbacks. If you goolge this keywords, you will only find articles about Magento 2. It seems as it some Magento developer created this error message. The error message comes directly from Magento 2 database pdo mysql layer in /vendor/magento/framework/DB/Adapter/Pdo/Mysql.php line 278:
1 | throw new \Exception(AdapterInterface::ERROR_ASYMMETRIC_ROLLBACK_MESSAGE); |
If a rollback should be done and transactionLevel is not set correctly this error is displayed. So you may contact your mysql database host to configure your database for Magento 2.
Conclusion
Asymmetric transaction rollback errors are strange, they have something to do with MySQL settings. The error sometimes appears and I was not able to reproduce it. Reindexing and cache clearing can solve this issue. If you write an import script you may need to create a fallback for such problems.
I do not see edit possibility so moderator can delete 1st message.
I have import script which loads data from xml and saves it as product in magento2 shop. My script imported more than 7000 products and now it throws me this error. This is happening during $_product->save(). Awkward is that It adds product to my shop but somewhere after that breaks my script with error. Tried with solution in this post but don’t work for me. One more thing, same script throws error on remote server but not on local (don’t have so much products on local – if it is important). Still trying to resolve this issue but if you have any ideas I will be grateful.
Have you tried my suggested solution to change /vendor/magento/framework/DB/Adapter/Pdo/Mysql.php? I’m not 100% sure why this happens, but it has to do with MySQL settings. It seems as if they are different on your local system and remote. MySQL doesn’t support rollbacks. The question is: why it needs to rollback your transaction. I discovered it too on product import. Sometimes it happens, sometimes not. Reason for this may be a 2nd running task on database which locks tables or a timeout from database. A deeper investigation would be grateful.
@magemaster “Have you tried my suggested solution to change /vendor/magento/framework/DB/Adapter/Pdo/Mysql.php?” – I’m magento2 beginner and do not feel worthy to change core 🙂 i tried something but without results.
I found solution it seems there is something wrong with indexres (at least in my case). In Admin Panel > System > Index Management I changed mode for each index to “update by schedule” and import is working now.