Model::createOrFirst()
in Postgres transaction may trigger SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current transaction is aborted, commands ignored until end of transaction block
#48143
Labels
Laravel Version
10.20.0
PHP Version
irrelevant
Database Driver & Version
PostgreSQL (Version: irrelevant)
Description
With the recent release of Laravel v10.20.0, due to #47973, there has been an overlap in functionality with my library: mpyw/laravel-retry-on-duplicate-key, which was originally designed to offer a feature now implemented by Laravel. Although this in itself is not an issue and I intend to update my library accordingly, I've identified a potential concern with how Laravel's new feature manages Postgres transactions.
Postgres has a distinctive behavior where, if an error occurs within a transaction, all subsequent queries fail unless the current transaction is rolled back or committed. However, this can be handled by setting a
SAVEPOINT
, which limits the rollback to that point. In my library, for Postgres and when the transaction level is greater than 0, I've incorporated a mechanism usingDB::transaction()
to create aSAVEPOINT
. If Laravel's new feature doesn't adopt a similar approach to handle Postgres transactions, it could lead to errors:SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current transaction is aborted, commands ignored until end of transaction block
.Steps To Reproduce
The text was updated successfully, but these errors were encountered: