-
Notifications
You must be signed in to change notification settings - Fork 403
Open
Description
PHP Version
8.4
Laravel Version
12.15
Package Version
14.0
Description
Root Cause
- Laravel Auditing attempts to create audit records during the transaction
- When an SQL error occurs inside the transaction, PostgreSQL enters a "failed transaction" state
- In this state, all subsequent commands are ignored, including the audit INSERT
- The audit still tries to save, generating the
25P02error
Error Message
SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current transaction is aborted,
commands ignored until end of transaction block
(Connection: pgsql, SQL: insert into "audits" ...)
```php
public function handle(PaymentStatusChanged $event)
{
try {
DB::beginTransaction();
$payment->status_code = 'CONCLUIDO';
$payment->save(); // Audit attempts to register here
// If an error occurs here, the transaction fails
$credit->addAmount($invalidAmount); // ERROR!
DB::commit();
} catch (\Exception $e) {
DB::rollBack(); // Too late, audit already tried to save
throw $e;
}
}
Steps To Reproduce
public function handle(PaymentStatusChanged $event)
{
try {
DB::beginTransaction();
$payment->status_code = 'CONCLUIDO';
$payment->save(); // Audit attempts to register here
// If an error occurs here, the transaction fails
$credit->addAmount($invalidAmount); // ERROR!
DB::commit();
} catch (\Exception $e) {
DB::rollBack(); // Too late, audit already tried to save
throw $e;
}
}Possible Solutions
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels