Commit aeb6265
committed
Fix security context missing in Doctrine entity listeners after kernel reboot
Persisting an EntityManager across kernel reboots binds its internal
ListenersInvoker to the old container. Lazy entity listeners then resolve
dependencies like security.token_storage from that stale container, making
the logged-in user invisible inside the listener while it is visible in the
controller. In pure Symfony (WebTestCase) there is no reboot, one container,
so the listener and the controller share the same security context.
Fix, in two parts that share one idea -- only the DBAL connection survives a
reboot; rebuild everything else on top of it from the current container:
- injectPersistentServices() no longer re-injects EntityManagerInterface or
ManagerRegistry instances. The freshly booted container rebuilds the
EntityManager on the persisted connection, preserving the open test
transaction while wiring every dependency (security included) to the
current request.
- _getEntityManager() resolves the EntityManager fresh from the current
container on every call instead of caching it as a permanent service. This
keeps the module's Doctrine helpers and the application on a single identity
map, matching pure Symfony, and avoids a stale cached manager after a reboot.
Only doctrine.dbal.default_connection stays persistent, which is what keeps
the transaction open.
Also rename persistDoctrineConnections() -> keepDoctrineConnectionsOpen() to
describe what it does: it removes the doctrine.connections parameter before
shutdown so DoctrineBundle::shutdown() cannot close the persisted connection
and drop the test transaction.
Fixes #341 parent 81c0365 commit aeb6265
2 files changed
Lines changed: 22 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
99 | | - | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
120 | 125 | | |
121 | 126 | | |
122 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
276 | 286 | | |
277 | 287 | | |
278 | 288 | | |
279 | 289 | | |
280 | 290 | | |
281 | 291 | | |
282 | | - | |
283 | | - | |
| 292 | + | |
284 | 293 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 294 | + | |
| 295 | + | |
289 | 296 | | |
290 | 297 | | |
291 | 298 | | |
292 | | - | |
| 299 | + | |
293 | 300 | | |
294 | 301 | | |
295 | 302 | | |
| |||
0 commit comments