Skip to content

Compatibility with Alice Data Fixtures #503

Closed
@colinodell

Description

@colinodell

Environment

PHP 7.4
Symfony 5.2
Doctrine DBAL 2.12.1
Doctrine ORM 2.8.4
theofidry/alice-data-fixtures 1.4.0
sentry/sentry 3.2.2
sentry/sentry-symfony 4.1.1

Steps to Reproduce

  • Use the dependencies above
  • Have automated functional tests that use Alice's PurgerLoader to purge the database before tests run
  • Upgrade sentry/sentry-symfony from 4.0.3 to 4.1.1
  • Run the tests

Expected Result

  • Alice detects that MySQL is being used and disables foreign key checks
  • Alice runs a series of TRUNCATE queries
  • All queries are successful
  • Functional tests begin running

Actual Result

  • Alice fails to detect that MySQL is being used; foreign key checks are not disabled
  • Alice runs a series of TRUNCATE queries
  • Queries fail due to FK constraints
  • Function tests fail to start

Alice uses the following code to determine if MySQL is being used:

public function purge()
{
    // Because MySQL rocks, you got to disable foreign key checks when doing a TRUNCATE/DELETE unlike in for example
    // PostgreSQL. This ideally should be done in the Purger of doctrine/data-fixtures but meanwhile we are doing
    // it here.
    // See the progress in https://github.com/doctrine/data-fixtures/pull/272
    $disableFkChecks = (
        $this->purger instanceof DoctrineOrmPurger
        && in_array($this->purgeMode->getValue(), [PurgeMode::createDeleteMode()->getValue(), PurgeMode::createTruncateMode()->getValue()])
        && $this->purger->getObjectManager()->getConnection()->getDriver() instanceof AbstractMySQLDriver
    );

    if ($disableFkChecks) {
        $connection = $this->purger->getObjectManager()->getConnection();

        $connection->exec('SET FOREIGN_KEY_CHECKS = 0;');
    }

    $this->purger->purge();

    if ($disableFkChecks && isset($connection)) {
        $connection->exec('SET FOREIGN_KEY_CHECKS = 1;');
    }
}

The AbstractMySQLDriver check fails because this bundle decorates the connection with Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnection which is not an instance of AbstractMySQLDriver. As a result, Alice can no longer identify the underlying driver in order to disable FK checks.

I believe this breaking change was introduced in #426 and is also causing #485 and #488. I suspect that code in other projects that relies on driver detection may also experience broken functionality as a result of the driver being decorated in this way.

Disabling the new DBAL tracing feature does seem to prevent the issue from occurring.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions