ClassMetadataFactory assert warning [orm] - TagMerge

ClassMetadataFactory assert warning [orm]

tasselchofAsked 4 months ago

BC Break Report

ClassMetadataFactory generates warnings because of assert, that was added in that version: https://github.com/doctrine/orm/blob/2.11.x/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php#L98

2022-01-10T16:30:25+00:00 WARN (4): assert(): assert($classMetadata instanceof ClassMetadata) failed {"errno":2,"file":"./vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php","line":98}

| Q | A |------------ | ------ | BC Break | yes | Version | 2.11.x

Source: link

greg0ireAnswered 4 months ago

This was introduced in https://github.com/doctrine/orm/pull/9274 , cc @derrabus I think it could be that $classMetadata is an instance of ClassMetadataInfo here? Can you debug this? Also, can you please provide a stack trace? Here is how to get one: https://symfony.com/doc/current/contributing/code/stack_trace.html

tasselchofAnswered 4 months ago

I think this have something to do with #8366. I mean the reason I am getting it is there: DateTime is passed to this function:

#0  Doctrine\ORM\Mapping\ClassMetadataFactory->onNotFoundMetadata() called at [./vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:282]
#1  Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:307]
#2  Doctrine\ORM\EntityManager->getClassMetadata() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3099]
#3  Doctrine\ORM\UnitOfWork->getSingleIdentifierValue() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:432]
#4  Doctrine\ORM\AbstractQuery->processParameterValue() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:456]
#5  Doctrine\ORM\Query->resolveParameterValue() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:400]
#6  Doctrine\ORM\Query->processParameterMappings() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/Query.php:316]
#7  Doctrine\ORM\Query->_doExecute() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:1181]
#8  Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:1135]
#9  Doctrine\ORM\AbstractQuery->execute() called at [./vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:923]
#10 Doctrine\ORM\AbstractQuery->getOneOrNullResult() called at [./module/Application/src/Repository/Traits/DefaultRepository.php:237]
#11 Software\Reports\Repository\Reports->findOneBy() called at [./module/Software/Software-accounts/src/Reports/FinanceMonthly.php:189]
#12 Software\Accounts\Reports\FinanceMonthly->cronCreateReports()
#13 call_user_func() called at [./module/Software/Software-reports/src/Controller/Console/ConsoleController.php:96]
#14 Software\Reports\Controller\Console\ConsoleController->reportCreateAction() called at [./vendor/laminas/laminas-mvc/src/Controller/AbstractActionController.php:71]
#15 Laminas\Mvc\Controller\AbstractActionController->onDispatch() called at [./vendor/laminas/laminas-eventmanager/src/EventManager.php:319]
#16 Laminas\EventManager\EventManager->triggerListeners() called at [./vendor/laminas/laminas-eventmanager/src/EventManager.php:179]
#17 Laminas\EventManager\EventManager->triggerEventUntil() called at [./vendor/laminas/laminas-mvc/src/Controller/AbstractController.php:97]
#18 Laminas\Mvc\Controller\AbstractController->dispatch() called at [./vendor/laminas/laminas-mvc-console/src/Controller/AbstractConsoleController.php:57]
#19 Laminas\Mvc\Console\Controller\AbstractConsoleController->dispatch() called at [./vendor/laminas/laminas-mvc/src/DispatchListener.php:132]
#20 Laminas\Mvc\DispatchListener->onDispatch() called at [./vendor/laminas/laminas-eventmanager/src/EventManager.php:319]
#21 Laminas\EventManager\EventManager->triggerListeners() called at [./vendor/laminas/laminas-eventmanager/src/EventManager.php:179]
#22 Laminas\EventManager\EventManager->triggerEventUntil() called at [./vendor/laminas/laminas-mvc/src/Application.php:325]
#23 Laminas\Mvc\Application->run() called at [./bin/Software:29]
./vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:100:

And I tried to understand what className is passed and found that:

Doctrine\Persistence\Mapping\MappingException: The class 'DateTime' was not found in the chain configured namespaces Application\Entity, Users\Entity in /home/dev/domains/alpha.orderadmin.ru/vendor/do"...
derrabusAnswered 4 months ago

I think it could be that $classMetadata is an instance of ClassMetadataInfo here?

I suspect that $classMetadata could be null here. The event is fired if no metadata could be retrieved and it should be possible that we still have no metadata after processing the event.

derrabusAnswered 4 months ago

Can you please try out #9355?

tasselchofAnswered 4 months ago

@derrabus yes, this fixes it.

derrabusAnswered 4 months ago

Thank you for your bug report. Yery good catch. 🙂

tasselchofAnswered 4 months ago

I am grad it helped. Thank you for fast fix. 😀

Recent Issues

    Programming Languages