Framework: Throw exception when committing and no transaction is started

Created on 11 Aug 2019  路  11Comments  路  Source: laravel/framework

  • Laravel Version: master (is a "feature" since #14085 / 5.2)
  • PHP Version: irrelevant
  • Database Driver & Version: irrelevant

Description:

https://github.com/laravel/framework/blob/e778e3296dce73fddf772844158a8c87f1857bb5/src/Illuminate/Database/Concerns/ManagesTransactions.php#L154-L163

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...

bug

Most helpful comment

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

All 11 comments

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!

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)

@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?

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

A pr for this fixed this for 6.0: https://github.com/laravel/framework/pull/29067

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().

@digilist right! My bad, sorry.

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

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.

@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?

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

progmars picture progmars  路  3Comments

kerbylav picture kerbylav  路  3Comments

gabriellimo picture gabriellimo  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments