Problem/Motivation

We're not disabling tracking of resources properly in \Drupal\Core\DependencyInjection\ContainerBuilder::__construct(). This can create unexpected differences in the container.

Proposed resolution

Swap the order of calls.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
861 bytes
1.45 KB
alexpott’s picture

Let's isolate the test so the class alias can not impact any other test or anything else.

The last submitted patch, 2: 2940956-2.test-only.patch, failed testing. View results

alexpott’s picture

Doh a typo slipped in.

alexpott’s picture

The constructor was added in #2284103: Remove the request from the container. The diff was:

diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
index 56f1627ed5..58cbe3cc85 100644
--- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
+++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
@@ -10,6 +10,7 @@
 use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
 use Symfony\Component\DependencyInjection\Container as SymfonyContainer;
 use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

 /**
  * Drupal's dependency injection container builder.
@@ -19,13 +20,11 @@
 class ContainerBuilder extends SymfonyContainerBuilder {

   /**
-   * Overrides Symfony\Component\DependencyInjection\ContainerBuilder::addObjectResource().
-   *
-   * Drupal does not use Symfony's Config component, so we override
-   * addObjectResource() with an empty implementation to prevent errors during
-   * container compilation.
+   * {@inheritdoc}
    */
-  public function addObjectResource($object) {
+  public function __construct(ParameterBagInterface $parameterBag = NULL) {
+    $this->setResourceTracking(FALSE);
+    parent::__construct($parameterBag);
   }

   /**

This was fine up until Symfony 2.6 but was changed in 2.7. At the time of #2284103: Remove the request from the container we were on "symfony/dependency-injection": "2.4.*",

alexpott’s picture

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

> This can create unexpected differences in the container.

Would be helpful to describe how exactly.

I can see on the docblock of the method something about not using symfony/config, which we certainly aren't. The parent uses "$this->trackResources = interface_exists('Symfony\Component\Config\Resource\ResourceInterface');". So my guess is that this is not a problem with plain core as we don't have that class. However, on an actual project, I see that we have that because behat as well as console-core depend on it.

Nice trick in the test with the class alias :)

  • larowlan committed 33e0ba3 on 8.6.x
    Issue #2940956 by alexpott: Properly disable resource tracking in the...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 33e0ba3 and pushed to 8.6.x

Cherry-picked as 7da71a2 and pushed to 8.5.x

  • larowlan committed 7da71a2 on 8.5.x
    Issue #2940956 by alexpott: Properly disable resource tracking in the...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.