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

Run risky code in finally block #11646

Merged
merged 2 commits into from
Oct 10, 2024
Merged

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Oct 9, 2024

catch blocks are not supposed to fail. If you want to do something despite an exception happening, you should do it in a finally block.

(finally) Fixes #7545

@greg0ire
Copy link
Member Author

greg0ire commented Oct 9, 2024

Should I move the call to commit() inside the finally block as well? 🤔

SenseException
SenseException previously approved these changes Oct 9, 2024
Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I move the call to commit() inside the finally block as well? 🤔

I don't know. It looks like it would all be the same in your changes. Logically, from a reading perspective, it would look weird if the commit would be in finally

Does anyone know why $conn->isTransactionActive() wasn't used in the EntityManager in the past?

catch blocks are not supposed to fail. If you want to do something
despite an exception happening, you should do it in a finally block.

Closes doctrine#7545
@greg0ire
Copy link
Member Author

I talked a bit more with @alcaeus and it wouldn't be problematic from a reading perspective only: if an exception happens after the actual commit, you don't want to rollback. I'll try adding the guard clause as well as tests.

It maybe happen that the SQL COMMIT statement is successful, but then
something goes wrong. In that kind of case, you do not want to attempt a
rollback.

This was implemented in UnitOfWork::commit(), but for some reason not in
the similar EntityManager methods.
@derrabus derrabus added this to the 2.19.8 milestone Oct 10, 2024
@greg0ire greg0ire merged commit c2c5000 into doctrine:2.19.x Oct 10, 2024
58 checks passed
@greg0ire greg0ire deleted the finally-fix-bug branch October 10, 2024 09:46
derrabus pushed a commit to doctrine/dbal that referenced this pull request Oct 11, 2024
<!-- Fill in the relevant information below to help triage your pull
request. -->

|      Q       |   A
|------------- | -----------
| Type         | bug
| Fixed issues | #4846

#### Summary

Let's do the same thing as for ORM in
doctrine/orm#11646

This somehow solves issue we tried to resolve in
#4846 by providing original
exception in Previous.
xabbuh added a commit to symfony/symfony that referenced this pull request Oct 17, 2024
This PR was merged into the 5.4 branch.

Discussion
----------

synchronize line numbers in deprecations baseline

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

line numbers changed in doctrine/orm#11646

Commits
-------

c31d79a synchronize line numbers in deprecations baseline
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