-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
We are using magento 2.3 instance on production and we have faced issue with transactions while saving some model to database. But when error happens we can`t log that to database because of transaction level.
Examples (*)
Lets look at https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php save function
At line 402 we have beginTransaction method. It sets transaction level from 0 to 1 level.
If on the next code some Error happend ( any of this https://www.php.net/manual/en/class.typeerror.php)
It is important that we are faced not an Exception, we are faced an Error object
And catch at line 432 - catchs only Exceptions
It means that transactions will never be rollbacked and the next pieces of code will save nothing to database because of that if we will use same connection instance.
Steps to reproduce (*)
- Write declare(strict_types=1) at the beginning of file https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php - this step is only for reproduce
- After $this->beginTransaction(); in save method write preg_match('/\d{10}/', 123); - this step is only for reproduce
- Save some entity programmatically or any other way.
- Debug this code and see that when preg_match will be executed, we will not catch that error and we will not rollback transaction here https://i.imgur.com/36hC27c.png
Proposed solution
I propose replace catch (\Exception $e) with catch (\Throwable $e).
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users with no workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.