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

[5.8] Throw Error If Transaction Is Not Started While Commit #29693

Closed
wants to merge 1 commit into from

Conversation

aman00323
Copy link

This pull request has the solution to bug User commit when there is no transaction started
The current code never notify user that transaction is not started and they are trying to commit.

Current 5.8 Code

        if ($this->transactions == 1) {
            $this->getPdo()->commit();
        }
        $this->transactions = max(0, $this->transactions - 1);
        $this->fireConnectionEvent('committed');

This could be disaster if someone forget to start transaction and they trying to commit, So changes in code will throw exception. That will indicate developer that they are trying to commit but no transaction has started yet.

Changes done to code

        if ($this->transactions == 1) {
            $this->getPdo()->commit();
        } elseif ($this->transactions == 0) {
            throw new TransactionException;
        } else {
            $this->transactions = max(0, $this->transactions - 1);
            $this->fireConnectionEvent('committed');
        }

This issue is already reported here #29505, and also this issue was mention earlier by @GrahamCampbell

@taylorotwell have look at this issue and it's PR.

Copy link
Contributor

@mfn mfn left a comment

Choose a reason for hiding this comment

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

I'm still not convinced this should be pushed into a minor release (ref: #29649 (comment) ) due to the breaking change.

Even if it's currently wrong, it's never nice to break peoples app during a minor upgrade and it seems this behaviour was there for a long time so there is no "rush" (at 6.0 is around the corner was we all know).

TL;DR: IMHO this is better suited for 6.0

@@ -155,11 +156,12 @@ public function commit()
{
if ($this->transactions == 1) {
$this->getPdo()->commit();
} elseif ($this->transactions == 0) {
throw new TransactionException;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to add a message here, given more detail why it can't be commited (because none was started)

@deleugpn
Copy link
Contributor

deleugpn commented Aug 23, 2019

High potential for breaking several applications on a point release, no?

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

Successfully merging this pull request may close these issues.

4 participants