Skip to content

Commit b858c61

Browse files
committed
refactor(database): address transaction helper review feedback
- document disabled transaction pass-through behavior - log original callback exception when rollback throws - remove stale DBDebug test helper warning Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent ad86f80 commit b858c61

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

system/Database/BaseConnection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,10 @@ public function transaction(callable $callback): mixed
10901090
} catch (Throwable $e) {
10911091
try {
10921092
$this->transRollback();
1093+
} catch (Throwable $rollbackException) {
1094+
log_message('error', 'Database: Transaction callback threw an exception before rollback failed: ' . $e);
1095+
1096+
throw $rollbackException;
10931097
} finally {
10941098
if ($this->transDepth > 0) {
10951099
$this->transStatus = false;

tests/system/Database/Live/TransactionClosureTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ protected function setUp(): void
4242

4343
/**
4444
* Sets $DBDebug to false.
45-
*
46-
* WARNING: this value will persist! take care to roll it back.
4745
*/
4846
protected function disableDBDebug(): void
4947
{
@@ -211,6 +209,7 @@ public function testRollbackCallbackExceptionBubblesWhenCallbackExceptionTrigger
211209
$this->assertSame('Rollback callback failed.', $e->getMessage());
212210
}
213211

212+
$this->assertLogContains('error', 'Transaction callback failed.');
214213
$this->dontSeeInDatabase('job', ['name' => 'Rolled Back Job']);
215214
}
216215

user_guide_src/source/database/transactions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ return value. If the transaction cannot begin, or if a query failure marks the
6868
transaction as failed without throwing an exception, ``transaction()`` rolls
6969
back and returns ``false``.
7070

71+
If transactions are disabled, ``transaction()`` does not start a transaction.
72+
It runs the callback and returns the callback result.
73+
7174
If the callback throws an exception, ``transaction()`` rolls back and rethrows
7275
the original exception.
7376

0 commit comments

Comments
 (0)