Commit a123a45
committed
bug symfony#57816 [DoctrineBridge] fix messenger bus dispatch inside an active transaction (IndraGunawan)
This PR was squashed before being merged into the 5.4 branch.
Discussion
----------
[DoctrineBridge] fix messenger bus dispatch inside an active transaction
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License | MIT
it was working fine with the below config and command.
```yaml
# config/packages/messenger.yaml
framework:
messenger:
buses:
sync_bus:
middleware:
- validation
- doctrine_ping_connection
- doctrine_close_connection
- doctrine_open_transaction_logger
- doctrine_transaction
routing:
App\Message\SyncJob: sync
```
```php
<?php
// src/Command/TestComand.php
namespace App\Command;
use App\Message\SyncJob;
use Doctrine\ORM\EntityManagerInterface;
// use ...
#[AsCommand(
name: 'app:test',
description: 'Add a short description for your command',
)]
class TestCommand extends Command
{
public function __construct(
private readonly EntityManagerInterface $em,
private readonly MessageBusInterface $bus,
)
{
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$this->bus->dispatch(new SyncJob('someone'));
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
return Command::SUCCESS;
}
}
```
An issue occurs if I dispatch the message inside a transaction
```php
$this->em->wrapInTransaction(function ($em) {
// another process here
$this->bus->dispatch(new SyncJob('someone'));
});
```
an error comes up
```
ERROR [app] A handler opened a transaction but did not close it.
```
This PR aims to fix this issue without changing the existing behaviour
Commits
-------
f164370 [DoctrineBridge] fix messenger bus dispatch inside an active transactionFile tree
2 files changed
+5
-4
lines changed- src/Symfony/Bridge/Doctrine
- Messenger
- Tests/Messenger
2 files changed
+5
-4
lines changedLines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
0 commit comments