-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] wither calls break services when used in certain configurations #48814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I experience a problem which may be similar, with a complex configuration of With symfony/dependency-injection on 5.4.17, the kernel "prepares" the EntityManager like this: /**
* Gets the public 'doctrine.orm.default_entity_manager' shared service.
*
* @return \Doctrine\ORM\EntityManager
*/
protected function getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true)
{
$a = ($this->services['doctrine.dbal.default_connection'] ?? $this->getDoctrine_Dbal_DefaultConnectionService());
if (isset($this->services['doctrine.orm.default_entity_manager'])) {
return $this->services['doctrine.orm.default_entity_manager'];
}
$b = new \Doctrine\ORM\Configuration();
$c = new \Doctrine\Persistence\Mapping\Driver\MappingDriverChain();
$d = ($this->privates['doctrine.orm.default_annotation_metadata_driver'] ?? $this->getDoctrine_Orm_DefaultAnnotationMetadataDriverService());
$c->addDriver($d, 'App\\Entity');
$c->addDriver($d, 'Chill\\MainBundle\\Entity');
$c->addDriver($d, 'Chill\\PersonBundle\\Entity');
$c->addDriver($d, 'Chill\\CustomFieldsBundle\\Entity');
$c->addDriver($d, 'Chill\\ActivityBundle\\Entity');
$c->addDriver($d, 'Chill\\DocStoreBundle\\Entity');
$c->addDriver($d, 'Chill\\DocGeneratorBundle\\Entity');
$c->addDriver($d, 'Chill\\AsideActivityBundle\\Entity');
$c->addDriver($d, 'Chill\\CalendarBundle\\Entity');
$c->addDriver($d, 'Chill\\TaskBundle\\Entity');
$c->addDriver($d, 'Chill\\ThirdPartyBundle\\Entity');
$c->addDriver($d, 'Chill\\BudgetBundle\\Entity');
// here, an exception is thrown because the configuration ($b) does not contains a mapping driver,
// which is added later in the function
$this->services['doctrine.orm.default_entity_manager'] = $instance = new \Doctrine\ORM\EntityManager($a, $b);
(new \Doctrine\Bundle\DoctrineBundle\ManagerConfigurator([], []))->configure($instance);
$b->setEntityNamespaces(['App' => 'App\\Entity', 'ChillMainBundle' => 'Chill\\MainBundle\\Entity', 'ChillPersonBundle' => 'Chill\\PersonBundle\\Entity', 'ChillCustomFieldsBundle' => 'Chill\\CustomFieldsBundle\\Entity', 'ChillActivityBundle' => 'Chill\\ActivityBundle\\Entity', 'ChillDocStoreBundle' => 'Chill\\DocStoreBundle\\Entity', 'ChillDocGeneratorBundle' => 'Chill\\DocGeneratorBundle\\Entity', 'ChillAsideActivityBundle' => 'Chill\\AsideActivityBundle\\Entity', 'ChillCalendarBundle' => 'Chill\\CalendarBundle\\Entity', 'ChillTaskBundle' => 'Chill\\TaskBundle\\Entity', 'ChillThirdPartyBundle' => 'Chill\\ThirdPartyBundle\\Entity', 'ChillBudgetBundle' => 'Chill\\BudgetBundle\\Entity']);
$b->setMetadataCache(new \Symfony\Component\Cache\Adapter\ArrayAdapter());
$b->setQueryCache(($this->privates['cache.doctrine.orm.default.query'] ?? $this->getCache_Doctrine_Orm_Default_QueryService()));
$b->setResultCache(($this->privates['cache.doctrine.orm.default.result'] ?? $this->getCache_Doctrine_Orm_Default_ResultService()));
/// here is added the missing metadata driver
$b->setMetadataDriverImpl($c);
$b->setProxyDir(($this->targetDir.''.'/doctrine/orm/Proxies'));
$b->setProxyNamespace('Proxies');
$b->setAutoGenerateProxyClasses(true);
$b->setSchemaIgnoreClasses([]);
$b->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
$b->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
$b->setNamingStrategy(new \Doctrine\ORM\Mapping\DefaultNamingStrategy());
$b->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy());
$b->setEntityListenerResolver(($this->services['doctrine.orm.default_entity_listener_resolver'] ?? $this->getDoctrine_Orm_DefaultEntityListenerResolverService()));
$b->setRepositoryFactory( /* etc. etc. */)
$b->addCustomHydrationMode('chill_flat_hierarchy_list', 'Chill\\MainBundle\\Doctrine\\ORM\\Hydration\\FlatHierarchyEntityHydrator');
$b->addCustomStringFunction('GET_PERSON_ADDRESS_ADDRESS_ID', 'Chill\\PersonBundle\\Doctrine\\DQL\\AddressPart\\AddressPartAddressId');
// ...
// add a lot of other custom function there ...
// ...
return $instance;
} This cause a bug because the EntityManager instance is created too early:
If I move those two lines at the end of the method, just before the protected function getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true)
{
// ...
$this->services['doctrine.orm.default_entity_manager'] = $instance = new \Doctrine\ORM\EntityManager($a, $b);
(new \Doctrine\Bundle\DoctrineBundle\ManagerConfigurator([], []))->configure($instance);
return $instance;
} If I downgrade symfony/dependency-injection to 5.4.16 ( EDIT 30/12/22 add comment in code block and correct version mismatch |
This comment was marked as off-topic.
This comment was marked as off-topic.
I also experience a similar problem with the doctrine configuration when I add an extra entity manager. After the update te symfony/dependency-injection 5.4.17 I get this error: I could trace the problem back to commit 58f2988 where in the PhpDumper the private function collectCircularReferences(string $sourceId, array $edges, array &$checkedNodes, array &$loops = [], array $path = [], bool $byConstructor = true): void
{
$path[$sourceId] = $byConstructor;
$checkedNodes[$sourceId] = true;
foreach ($edges as $edge) {
$node = $edge->getDestNode();
$id = $node->getId();
if ($sourceId === $id || !$node->getValue() instanceof Definition || $edge->isWeak()) {
continue;
}
//..
} When I add the private function collectCircularReferences(string $sourceId, array $edges, array &$checkedNodes, array &$loops = [], array $path = [], bool $byConstructor = true): void
{
$path[$sourceId] = $byConstructor;
$checkedNodes[$sourceId] = true;
foreach ($edges as $edge) {
$node = $edge->getDestNode();
$id = $node->getId();
if ($sourceId === $id || !$node->getValue() instanceof Definition || $edge->isLazy() || $edge->isWeak()) {
continue;
}
//..
} |
This comment was marked as off-topic.
This comment was marked as off-topic.
@julienfastre @axi @HeinDR I'm pretty sure the problem you're talking about is a different issue. |
@cs278 Ah sorry, I looked at @julienfastre comment and that seems to be the same problem and I also could get my issue sort of fixed with his fix. |
Ouch, sorry, I opened a new issue #48895 |
…-grekas) This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Fix dumping inlined withers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48814 | License | MIT | Doc PR | - Commits ------- 455ace0 [DependencyInjection] Fix dumping inlined withers
Symfony version(s) affected
4.4.49, 5.4.17 (those I've reproduced the issue on)
Description
Configuring a service that uses the wither pattern, added in #30212, can break the dumped PHP container with more complex configurations. The inlined service that uses the wither pattern for some reason is written into the container with the service ID of the dependant service, most of the time it is subsequently replaced by the correct implementation but in some configurations this does not happen.
As an example this YAML generates the following method:
As I said above in some situations, the correct initialisation of
$container->privates['App\\TestCommand']
is done before instead of after which then breaks other services as they get completely the wrong class.How to reproduce
I've not managed to create a simple reproducer, but I do have one based on the Sentry Symfony bundle which is how I found this problem in the first place. https://github.com/cs278/symfony-issue-48814
In this case the following service method is created:
Possible Solution
I've got a PR incoming with a fix.
Additional Context
Workaround until a fix is released is to make the service that uses the
returns_clone
tag public.The text was updated successfully, but these errors were encountered: