Skip to content

Commit

Permalink
Do not rollback only on exceptions where we know the transaction is n…
Browse files Browse the repository at this point in the history
…o longer active
  • Loading branch information
simPod committed Oct 14, 2024
1 parent b512770 commit 36e23d1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
use Doctrine\DBAL\Event\TransactionCommitEventArgs;
use Doctrine\DBAL\Event\TransactionRollBackEventArgs;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Exception\DeadlockException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
Expand Down Expand Up @@ -1298,7 +1300,11 @@ public function transactional(Closure $func)

$shouldRollback = false;
} catch (TheDriverException $t) {
$shouldRollback = false;
$convertedException = $this->handleDriverException($t, null);
$shouldRollback = ! (
$convertedException instanceof UniqueConstraintViolationException
|| $convertedException instanceof DeadlockException
);

Check warning on line 1307 in src/Connection.php

View check run for this annotation

Codecov / codecov/patch

src/Connection.php#L1302-L1307

Added lines #L1302 - L1307 were not covered by tests

throw $t;

Check warning on line 1309 in src/Connection.php

View check run for this annotation

Codecov / codecov/patch

src/Connection.php#L1309

Added line #L1309 was not covered by tests
} finally {
Expand Down

0 comments on commit 36e23d1

Please sign in to comment.