Description
Symfony version(s) affected: 5.1.0-BETA1
Description
The generated preload file throws PHP Fatal error: Cannot declare class Proxies\__CG__\App\Entity\SomeEntityName, because the name is already in use
. From what I can tell, the doctrine proxies are listed twice in the preload file. I tried debugging it and it looks like there are 2 pieces of code responsible for the bug:
- https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Kernel.php#L576
- https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php#L83
When running cache:warmup
the kernel is building the container and calling the cache warmers and appending to the preload file. After the kernel built the container, the cache:warmer command is also calling the cache:warmers and append to the preload file. This is how doctrine proxies get appended twice.
How to reproduce
It should be reproducible with symfony/demo
rm -rf var/cache/prod
APP_ENV=prod php bin/console cache:warmup
Possible Solution
I'd gladly submit a PR, but I have no idea how to fix this one.
Additional context
I also hit the issue reported in #35759. I had to set I'm running PHP 7.4.5.container.dumper.inline_class_loader=true
in order for my preload file to be generated.
Edit
I worked around the issue by skipping cache:warmup
and just calling bin/console (this way, the kernel does it's thing, but the cache:warmup
command won't append again).
Also, I was apparently wrong about setting container.dumper.inline_class_loader=true
. That will generate include
calls for hot path services and it will throw errors with preloading because all those files are already loaded. I have set container.dumper.inline_class_loader=false
and it fixed the issue. I don't know exactly why it wasn't generating the preload file before setting it to true
.