Skip to content

[DependencyInjection] ResolveChildDefinitionsPass with decorator stack #59186

Closed as not planned
@mtarld

Description

@mtarld

Symfony version(s) affected

6.4

Description

When defining services using stacks:

->stack('json_encoder.encode.property_metadata_loader', [
    inline_service(EncodeAttributePropertyMetadataLoader::class)
        ->args([
            service('.inner'),
            tagged_locator('json_encoder.normalizer'),
            service('type_info.resolver'),
        ]),
    // ...
])

And running Symfony CI in low deps, some tests using the ResolveChildDefinitionsPass are falling.

How to reproduce

Revert the https://github.com/symfony/symfony/pull/59179/files PR and run "PHP8.2 low-deps" tests.
This must end like https://github.com/symfony/symfony/actions/runs/12280275223/job/34266294785?pr=59177

Here is an example of the failure message:

1) Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\PhpFrameworkExtensionTest::testLockWithService
Symfony\Component\DependencyInjection\Exception\RuntimeException: Service "json_encoder.encode.property_metadata_loader": Parent definition "" does not exist.

Possible Solution

Seems like the bug is because the parent of the ChildDefinition is "".

A quick fix could be to change the following in ResolveChildDefinitionsPass:

protected function processValue(mixed $value, bool $isRoot = false): mixed
{
    if (!$value instanceof Definition) {
        return parent::processValue($value, $isRoot);
    }
    if ($isRoot) {
        // yes, we are specifically fetching the definition from the
        // container to ensure we are not operating on stale data
        $value = $this->container->getDefinition($this->currentId);
    }
-    if ($value instanceof ChildDefinition) {
+    if ($value instanceof ChildDefinition && $value->getParent()) {

        $this->currentPath = [];
        $value = $this->resolveDefinition($value);
        if ($isRoot) {
            $this->container->setDefinition($this->currentId, $value);
        }
    }

    return parent::processValue($value, $isRoot);
}

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy