Fix production cache:clear crash when DoctrineBundle's metadata warmer runs#136
Conversation
b5a3317 to
9c0b84c
Compare
There was a problem hiding this comment.
Pull request overview
This PR prevents production cache:clear crashes in apps using this bundle with Doctrine ORM by ensuring the Doctrine entity manager metadata factory is left in a clean state after MediaEntityMetadataWarmer runs, allowing DoctrineBundle’s metadata cache warmer to run afterwards without hitting a LogicException.
Changes:
- Reset all Doctrine managers at the end of
MediaEntityMetadataWarmer::warmUp()to avoid leaking loaded metadata into subsequent cache warmers. - Add an integration-style kernel test that runs the bundle’s warmer and then executes a real
DoctrineMetadataCacheWarmer, asserting it successfully writes its output file.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Cache/MediaEntityMetadataWarmer.php |
Resets the Doctrine managers after warming to avoid impacting later warmers that assume a clean metadata factory. |
tests/src/Cache/MediaEntityMetadataWarmerTest.php |
Adds coverage to verify DoctrineBundle’s metadata cache warmer can run after this bundle’s warmer without failing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@vvasiloi Thx for your proposal! I've fixed the PHPUnit test in the main branch. Could you rebase and apply Copilot suggestions please? |
Will do! |
getAllMetadata() loads every class metadata into the shared factory; DoctrineBundle's own metadata warmer is optional (runs after this one, in non-debug kernels) and throws 'DoctrineMetadataCacheWarmer must load metadata first' on a factory that already holds metadata — breaking every production cache:clear in apps using the bundle with Doctrine.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
c32caee to
638f113
Compare
|
I see @xavierlacot already did that! Thanks! 🥇 |
|
Nice, thanks @vvasiloi 🙏 |
MediaEntityMetadataWarmercallsgetAllMetadata(), which loads every class metadata into the shared factory. DoctrineBundle's ownDoctrineMetadataCacheWarmeris optional — it runs later, and only in non-debug kernels — and throwsDoctrineMetadataCacheWarmer must load metadata first, check priority of your warmerswhen the factory already holds metadata. Result: every productioncache:clearcrashes in apps using the bundle with Doctrine ORM (dev/CI never see it, so it surfaces on deploy).Fix: reset the entity managers after warming, so later warmers get a clean metadata factory.
The added test boots the test application, runs the bundle warmer, and then runs a real
DoctrineMetadataCacheWarmer— red on currentmain, green with the fix.