Skip to content

Magento can't rollback transactions while Test Transparent Transaction is still active #10163

@mhoerhold

Description

@mhoerhold

In short

Steps to reproduce

  • Magento Test "Magento\TestFramework\Db\Adapter\Mysql" opens a "TransparentTransaction"
  • Magento Core "Magento\Framework\DB\Adapter\Pdo\Mysql" opens a normal transaction
  • Magento Core "Magento\Framework\DB\Adapter\Pdo\Mysql" rollback the normal transaction
  • Magento Core "Magento\Framework\DB\Adapter\Pdo\Mysql" opens a new normal transaction
    • this causes an error because rollback isn't complete
    • getTransactionLevel() returns "0" but the value of "$this->_transactionLevel" is "1"

In detail

Preconditions

  1. Magento 2.1.6
  2. PHP 7.0.20
  3. MySQL 5.5.55

Steps to reproduce

  1. I wrote a Rest service which delegates bundled requests to the corresponding Rest Resource.
  2. To test this service I used the Integration Test FW.
  3. So I tried to handle two request in one method call:
    • Create an allready existing Admin User
    • Update an existing Admin User

Expected result

I expected that this method returns the following result:

  • Create faild > Magento\Framework\Validator\Exception : A user with the same user name or email already exists.
  • Successfully updated the user

Actual result

  1. But what I get is:
    • Create failed > Magento\Framework\Validator\Exception : A user with the same user name or email already exists.
    • Update failed > Exception: Rolled back transaction has not been completed correctly.
  2. The corresponding exceptions are:

Suggestion

The class variable "$this->_transactionLevel" shouldn't used directly. I think it's better to use getTransactionLevel() and add some protected methods e.g. "increaseTransactionLevel()" and "decreaseTransactionLevel()". This should avoid that problem, because you can override this methods inside Magento\TestFramework\Db\Adapter\Mysql.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: Cannot ReproduceCannot reproduce the issue on the latest `2.4-develop` branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedProgress: needs update

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions