-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
Should I move the call to |
There was a problem hiding this 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
a62c5df
to
51be1b1
Compare
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.
955a03d
to
b6137c8
Compare
<!-- 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.
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
catch
blocks are not supposed to fail. If you want to do something despite an exception happening, you should do it in afinally
block.(finally) Fixes #7545