-
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
Not throwing proper exception when in transaction #7545
Comments
I'd rather say that the failed rollback should have priority here, as something much worse is happening (no active transaction in first place). |
I forgot to mention that the whole operation is called within I see that it starts with Just checked that before calling After first PDOException with Unique violation is thrown, the transaction is no longer active. Most possibly because |
I decided to go with a test. Found out, that it works just fine. The problem is that in some cases, I defer unique constrains (eg. when doing full sync, running all CUD operations) When constraint is deferred, the violation is thrown during commit, not on flush and therefore the issue pops up. https://github.com/simPod/doctrine2/commit/cd031c84b7346fc264819b211e51f5d00408cc94 Tests pass when line :48 is commented out (constraint defer is disabled). |
@simPod I'd suggest tackling this within 3.x, by adding a better exception type that captures both rollback and previous failures. |
@grongor took over 👋 |
the original exception should not/never be swallowed, and it's a real prod debug issue we'll get an exception either way, i prefer the original one so i suggest tackling this within 2.x |
@ro0NL this was reported 6 years ago. Can you please provide a full stack trace of the exception you are getting now? I would like to know if it is still a |
Doctrine\DBAL\Exception\DriverException
previous: Doctrine\DBAL\Driver\PDO\Exception
previous previous: PDOException
|
Then I think a possible design could be defining Then, that extra exception could be displayed by the error handler… that could be an issue since it would mean the error handler would have to know about the wither. Another solution to that could be to clone the exception and modify its message. Sadly, this means this cannot be tackled in 2.x |
perhaps simply rethrow with original exception concatted in message? |
Yes, that's what I mean by "modify its message" (except I would use deep cloning). In the meantime, I think there is something you could try on your application to debug your urgent production issue with ORM 2 and DBAL 3: writing a DBAL middleware that catches, logs and rethrows any exception it sees go through. Note that since |
these are caused by postgres constraint issues, and are not currently handled well by doctrine: doctrine#7545
We've been seeing this issue. I'll add some context on what we've found:
We've seen two possible workarounds:
However in any case a proper solution for this issue would be, as suggested, to include the information of the previous exception somehow. Maybe with a specific exception class that handles exceptions happened during the handling of an exception like it's the case here. |
Hello from the doctrine hackathon 👋 I discussed this with the team, and @alcaeus told me that code inside a catch block should never fail. If it does, it might be because we are trying to do something despite the fact that an exception occurred. That kind of stuff should be done in a |
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
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
Bug Report
Summary
EntityManager tries to rollback the transaction when exception is thrown during commit operation. The rollback is performed through DBAL Connection. The problem is that the transaction is no longer active and when DBAL Connection tries to rollback through
PDOConnection
, There is no active transaction exception is thrown instead and the original exception is lost. So user has no easy way to know actual exception and gets There is no active transaction instead.Current behavior
PDOException
ASQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint ...
occurs on commit in https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/EntityManager.php#L238Connection::rollback()
is called where$this->_conn->rollBack();
is called._conn
is instance ofPDOConnection
that throws There is no active transaction exception instead and the original exception is lost.Expected behavior
The original exception is properly thrown.
The text was updated successfully, but these errors were encountered: