Replies: 1 comment
-
I've created a PR that aims to fix this: #53377 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I encountered unexpected errors after adding another database connection to
$connectionsToTransact
withRefreshDatabase
. Through testing and reading related issues, it appears that Laravel’safterCommit
handling still doesn’t fully support multi-database setups.Look at this example test case:
The reason lies in the
Illuminate\Foundation\Testing\DatabaseTransactionManager
, which skips root transactions when adding callbacks:With multiple connections, this logic only skips the root transaction for the default connection and mistakenly attaches the callback to the root transaction of the secondary connection. This behavior is functional with single databases but fails to handle multiple connections correctly, as the uncommitted secondary transaction prevents
afterCommit
from executing.The dedicated
DatabaseTransactionManager
for testing was introduced not a long time ago by #48523 to fix issues with nested connections and and was seen as a fix for issue #48472, which reported thatafterCommit
callbacks were not executed in tests withRefreshDatabase
and multiple database connections added to$connectionsToTransact
.I borrowed the first example test from this issue. So before the mentioned PR was merged, the first example test wasn't working either.
However, it seems inconsistent that the first test now passes, but the second fails, especially given that removing
other_connection
from$transactionsToTransact
will make it pass.Suggested Improvements:
Enhanced Skipping Logic: Skip all root transactions across active connections, allowing correct callback handling in multi-database environments.
Connection-Specific Callbacks:
DB::afterCommit()
could let users specify targeted connections, making DB::transaction() andDB::afterCommit()
work as expected with the default connection while preserving control over additional connections.These changes would align
afterCommit
behavior more intuitively with multi-database use cases.I would consider 1. as mandatory, since the current skipping logic is not sufficiently respecting multi database connection setups, 2. would be a nice improvement.
Beta Was this translation helpful? Give feedback.
All reactions