Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Fixtures are not loaded when autocommit mode is disabled #507

Open
Crovitche-1623 opened this issue Mar 29, 2025 · 1 comment
Open

Comments

@Crovitche-1623
Copy link

Crovitche-1623 commented Mar 29, 2025

Bug Report

Q A
Version 3.7.0

Summary

When the autocommit mode is disabled and save points are enabled, the fixtures cannot be loaded because the wrapInTransaction method from doctrine/orm/src/EntityManager.php begin a transaction without checking first if a transaction is active (which is done automatically when the connection is opened when autocommit is disabled). This is a problem because when save points are enabled because it adds savepoint and the fixtures are therefore never loaded.

Potential solution 1:

If I check if a transaction is active before starting a transaction, it works as expected. E.g. :

    public function wrapInTransaction(callable $func): mixed
    {
        if (!$this->conn->isTransactionActive()) {
            $this->conn->beginTransaction();
        }

        // ...
    }

Potential solution 2:

Create a dedicated EntityManager for migrations with autocommit disabled 😢

Moreover, I think transactions should not be automatically started or commited as I explained here: doctrine/dbal#6258 (comment)

@Crovitche-1623
Copy link
Author

Crovitche-1623 commented Apr 2, 2025

Moreover, I figured out that the problem is that a DDL commands (CREATE, ALTER, DROP...) automatically start transactions in MySQL when the autocommit mode is disabled.

Therefore, if an INSERT statement follows a CREATE command, nothing will be inserted because a COMMIT is missing. This causes the last migration to be not inserted even if the potential solution above solves partially the issue.

To be sure the doctrine migrations versions table were up to date, I had to wrap the $this->metadataStorage->complete($result); around $this->connection->transactional(...) in DbalExecutor L185 :

// ...

$this->connection->transactional(function () use ($result) {
    $this->metadataStorage->complete($result);
});

// ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant