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

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

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

simPod
Copy link
Contributor

@simPod simPod commented Oct 12, 2024

Q A
Type bug
Fixed issues #3423

Summary

#6543 partially solved what we tried to achieve in #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 #6546 (draft, does not contain review changes)

@simPod simPod marked this pull request as ready for review October 12, 2024 12:17
src/Connection.php Outdated Show resolved Hide resolved
simPod added a commit to simPod/dbal that referenced this pull request Oct 12, 2024
simPod added a commit to simPod/dbal that referenced this pull request Oct 12, 2024
simPod added a commit to simPod/dbal that referenced this pull request Oct 12, 2024
simPod added a commit to simPod/dbal that referenced this pull request Oct 12, 2024
simPod added a commit to simPod/dbal that referenced this pull request Oct 12, 2024
@simPod simPod requested a review from greg0ire October 12, 2024 14:48
simPod added a commit to simPod/dbal that referenced this pull request Oct 12, 2024
simPod added a commit to simPod/dbal that referenced this pull request Oct 12, 2024
src/Connection.php Show resolved Hide resolved
src/Connection.php Show resolved Hide resolved
@greg0ire
Copy link
Member

It seems there are CI jobs failing. Please take a look at this guide for more on how to handle those.

@simPod
Copy link
Contributor Author

simPod commented Oct 12, 2024

Thanks, just did not notice that basic stuff, u were faster 🙃 fixed.

simPod added a commit to simPod/dbal that referenced this pull request Oct 12, 2024
@simPod simPod force-pushed the df-c_v3 branch 3 times, most recently from 71e5b43 to 9879edf Compare October 13, 2024 10:15
@simPod simPod requested a review from greg0ire October 13, 2024 10:19
@simPod simPod force-pushed the df-c_v3 branch 2 times, most recently from ebc4aa1 to b512770 Compare October 13, 2024 11:20
@simPod simPod changed the title Fix incorrect handling of transactions when using deferred constraints Fix incorrect transactional() handling when DB auto-rolled back the transaction Oct 20, 2024
derrabus pushed a commit that referenced this pull request Oct 31, 2024
…6563)

|      Q       |   A
|------------- | -----------
| Type         | improvement
| Fixed issues | <!-- use #NUM format to reference an issue -->

#### Summary

Covers the concern expressed by @greg0ire
#6545 (comment)

This ensures the transaction is (not)active based on `autocommmit` mode
when interacting with `transactional()`.
@simPod simPod requested a review from greg0ire October 31, 2024 17:08
… transaction

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.

- Do not rollback only on exceptions where we know the transaction is no longer active
- Introduce TransactionRolledBack exception
- Transform Oracle's "transaction rolled back" exception and use the underlying one that DBAL supports
@morozov
Copy link
Member

morozov commented Nov 4, 2024

It will take me some time to understand the details in order to provide a meaningful feedback. Please feel free to merge it as is. The number of "line not covered by tests" warnings and enumeration of specific exception classes in handling a commit failure is a bit concerning, though. On the positive side, the fix doesn't introduce any new API, so if something goes seriously wrong, it will be safe to revert.

@simPod
Copy link
Contributor Author

simPod commented Nov 4, 2024

I guess there's some issue with coverage configuration since e.g. my test explicitly covers this line

image image

@greg0ire
Copy link
Member

greg0ire commented Nov 4, 2024

I think that for some reason, codecov only processes the reports from appveyor, and not from github-action. I have yet to figure out why.

@greg0ire greg0ire added this to the 3.9.4 milestone Nov 4, 2024
@greg0ire greg0ire added the Bug label Nov 4, 2024
@greg0ire greg0ire merged commit dd4601c into doctrine:3.9.x Nov 4, 2024
98 checks passed
@greg0ire
Copy link
Member

greg0ire commented Nov 4, 2024

Thanks @simPod 🎉

@simPod simPod deleted the df-c_v3 branch November 4, 2024 19:18
@simPod
Copy link
Contributor Author

simPod commented Nov 4, 2024

Let me know if you need help resolving v4 conflicts.

@greg0ire
Copy link
Member

greg0ire commented Nov 4, 2024

Thanks for offering your help, I do need it 🙏

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

Successfully merging this pull request may close these issues.

3 participants