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

Throw exception when committing and no transaction is started #29505

Closed
digilist opened this issue Aug 11, 2019 · 11 comments
Closed

Throw exception when committing and no transaction is started #29505

digilist opened this issue Aug 11, 2019 · 11 comments
Labels

Comments

@digilist
Copy link

digilist commented Aug 11, 2019

Description:

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

In cases where the user calls commit() more often than beginTransaction() (e.g. because beginTransaction() is removed by accident) the user will never notice.

This method should throw an exception instead, because otherwise the user will never notice (that the transaction has been committed to early or that no transaction is active at all).

@GrahamCampbell already pointed to that issue in #12382 and #14085 but was ignored...

@driesvints
Copy link
Member

Heya, thanks for submitting this.

This seems like a feature request or an improvement. It's best to post these at the laravel/ideas repository to get support for your idea. After that you may send a PR to the framework. Please only use this issue tracker to report bugs and issues with the framework.

Thanks!

@digilist
Copy link
Author

This is not a feature, it's a bug and can lead to serious data inconsistencies without anybody noticing it! (actually happend in the project I am currently working on)

@driesvints
Copy link
Member

@digilist then why did you mark this as "feature" in your issue template? Please try to properly fill out issue templates when posting them.

I think maybe an exception could indeed work here. Can you maybe send in a PR with a test?

@aman00323
Copy link

@driesvints I have created PR, it is first time i am contributing, please drive me if i have done something wrong thanks. :)

@driesvints
Copy link
Member

A pr for this fixed this for 6.0: #29067

@digilist
Copy link
Author

digilist commented Sep 2, 2019

This PR does not fix the handling of commit(), does it? It's only fixing another bug in the transaction method, but you can use commit() without using transaction().

@driesvints
Copy link
Member

@digilist right! My bad, sorry.

@BobMali
Copy link

BobMali commented Oct 4, 2019

@driesvints I have opened a PR on this issue. First time contributor here, please be gentle. 😄

@driesvints
Copy link
Member

Unfortunately we've decided that we won't be pursuing a fix for this, sorry. The risk that it'd break apps is too great.

@digilist
Copy link
Author

@driesvints So having a bug that might silently lead to inconsistent databases is better than forcing some users to fix this? Why not start at least with logging on critical level and later convert it to an exception?

@driesvints
Copy link
Member

@digilist I'm sorry but we had to weigh against the downside of this breaking apps. You're free to open an issue on the ideas repo to think about alternative solutions or what's your proposing in the above comment.

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

No branches or pull requests

4 participants