dbal icon indicating copy to clipboard operation
dbal copied to clipboard

Fix incorrect `transactional()` handling when DB auto-rolled back the transaction

Open simPod opened this issue 1 year ago • 18 comments
trafficstars

Q A
Type bug
Fixed issues #3423

Summary

https://github.com/doctrine/dbal/pull/6543 partially solved what we tried to achieve in https://github.com/doctrine/dbal/pull/4846. With that There's no active transaction exception contains the actual exception in $previous.

Now, let's get rid of There's no active transaction exception which occurs e.g. when using deferred constraints so the violation is checked at the end of the transaction and not during it. Database then rolls back the transaction automatically.

The current faulty flow is following:

  1. on commit(), Constrain violation occurs
  2. transaction is implicitly aborted and rolled back in database
  3. DBAL calls rollback()
  4. Since there's no active transaction, There's no active transaction exception is thrown:
image

This PR adjusts the flow so:

  1. on commit(), Constrain violation occurs
  2. transaction is implicitly aborted and rolled back in database
  3. DBAL DOES NOT call rollback() 🥳

For DBAL v4 it looks like this https://github.com/doctrine/dbal/pull/6546 (draft, does not contain review changes)

simPod avatar Oct 12 '24 12:10 simPod