doctrine / DoctrineMongoDBBundle

Integrates Doctrine MongoDB ODM with Symfony
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
MIT License
379 stars 229 forks source link

Class load error bug #740

Closed vassdavid closed 2 years ago

vassdavid commented 2 years ago

Problem: run cache:clear in symfony app when I define Document sometimes give class load error, but class exist and imported. Possible problem case: define two class in one folder, one namespace: A, B if A extends B -> make ClassNotFoundError But if B extends A -> working

I think the problem is caused by file loading, since the classes further back in name order are not loaded. I always get this problem when extend and use trait in document.

env: docker php:8.1.7-fpm image version: 4.5.0 exception: [Symfony\Component\ErrorHandler\Error\ClassNotFoundError]

trace: require_once() at /app/vendor/doctrine/persistence/src/Persistence/Mapping/Driver/ColocatedMappingDriver.php:189 Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver->getAllClassNames() at /app/vendor/doctrine/persistence/src/Persistence/Mapping/Driver/MappingDriverChain.php:104 Doctrine\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() at /app/vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php:94 Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() at /app/vendor/doctrine/mongodb-odm-bundle/CacheWarmer/ProxyCacheWarmer.php:90 Doctrine\Bundle\MongoDBBundle\CacheWarmer\ProxyCacheWarmer->getClassesForProxyGeneration() at /app/vendor/doctrine/mongodb-odm-bundle/CacheWarmer/ProxyCacheWarmer.php:78 Doctrine\Bundle\MongoDBBundle\CacheWarmer\ProxyCacheWarmer->warmUp() at /app/vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:99 Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /app/vendor/symfony/http-kernel/Kernel.php:577 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /app/vendor/symfony/http-kernel/Kernel.php:767 Symfony\Component\HttpKernel\Kernel->preBoot() at /app/vendor/symfony/http-kernel/Kernel.php:128 Symfony\Component\HttpKernel\Kernel->boot() at /app/vendor/symfony/http-kernel/Kernel.php:146 Symfony\Component\HttpKernel\Kernel->reboot() at /app/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:235 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /app/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:154 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /app/vendor/symfony/console/Command/Command.php:308 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/console/Application.php:1016 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/framework-bundle/Console/Application.php:94 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /app/vendor/symfony/console/Application.php:299 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/framework-bundle/Console/Application.php:80 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/console/Application.php:171 Symfony\Component\Console\Application->run() at /app/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /app/vendor/autoload_runtime.php:29 require_once() at /app/bin/console:11

malarzm commented 2 years ago

The bundle does nothing on its own to load documents, everything is happening through composer's autoloading in the default setup. There's little we can do to help, most often the case I've seen is case-sensitive filesystem and class name not 100% on par with the filename. Try using the class somewhere else (i.e. not through Doctrine) and maybe you'll be able to pinpoint the issue.