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

Laravel 9: DB::transactionLevel() shows incorrect level, if DDL operation was done #48776

Closed
mrckzgl opened this issue Oct 19, 2023 · 2 comments

Comments

@mrckzgl
Copy link

mrckzgl commented Oct 19, 2023

Laravel Version

9.20.0

PHP Version

8.2.1

Database Driver & Version

10.10.2-MariaDB-1:10.10.2+maria~ubu2204

Description

We encounter that DB::transactionLevel() shows an incorrect level after a DDL operation was done, which does commit implicitly. Consider this code snippet which is the current behaviour:

Log::debug(DB::transactionLevel()); // 0
DB::beginTransaction();
Log::debug(DB::transactionLevel()); // 1
DB::commit();
Log::debug(DB::transactionLevel()); // 0

DB::beginTransaction();
Log::debug(DB::transactionLevel()); // 1
// some DDL operation which closes the transaction
Log::debug(DB::transactionLevel()); // 1

This is problematic on different levels. First, getting the correct transaction level is important to be able to close all pending transactions. Second, due to a current change (see: #35380), DB::commit() and DB::rollback() both throw an exception if no active transaction is present. That means after beginTransaction and a DDL statement, this code:

if (DB::transactionLevel() > 0) {
  DB::commit();
}

will fail.

Steps To Reproduce

DB::beginTransaction();
// do some DDL statement
if (DB::transactionLevel() > 0) {
  DB::commit();
}

If necessary I could construct a minimal working example (but woudn't mind if it is not needed).

@driesvints
Copy link
Member

Hey there,

Unfortunately we don't support this version anymore. Please check out our support policy on which versions we are currently supporting. Can you please try to upgrade to the latest version and see if your problem persists? If so, please open up a new issue and we'll help you out.

Thanks!

@mrckzgl mrckzgl changed the title DB::transactionLevel() shows incorrect level, if DDL operation was done Laravel 9: DB::transactionLevel() shows incorrect level, if DDL operation was done Oct 19, 2023
@mrckzgl
Copy link
Author

mrckzgl commented Oct 19, 2023

@driesvints I just confirmed this is happening in Laravel 10 too, see: #48777

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

No branches or pull requests

2 participants