Problem/Motivation

As per #2976394: Allow Symfony 4.4 to be installed in Drupal 8, various things are failing with this deprecation:

1x: The "Drupal\Component\DependencyInjection\Container" class implements "Symfony\Component\DependencyInjection\ResettableContainerInterface" that is deprecated since Symfony 4.2, use "Symfony\Contracts\Service\ResetInterface" instead.
    1x in EntityAccessCheckTest::setUp from Drupal\Tests\Core\Entity

Unfortunately Symfony\Contracts\Service\ResetInterface does not exist in Symfony 3.4, so we cannot directly use that yet. Looks like we need to put this on an ignore list, introduce a ResetInterface of our own until we depend on Symfony 4 or stop implementing ResettableContainerInterface. If we add our own ResetInterface, then people may start to typehint/depend on that which would be an unintended side effect though.

Proposed resolution

Stop using ResettableContainerInterface in Drupal\Component\DependencyInjection\Container. Keep the method's implementation.

Remaining tasks

Commit.

User interface changes

None.

API changes

ResettableContainerInterface in no longer used on Drupal\Component\DependencyInjection\Container. The reset() method is kept though. Code type-hinting on ResettableContainerInterface will break. We did not find contrib modules that type-hinted on it.

Data model changes

None.

Release notes snippet

Drupal\Component\DependencyInjection\Container no longer implements Symfony\Component\DependencyInjection\ResettableContainerInterface for future compatibility with Symfony 5. If you are type-hinting on this interface, update your type-hint to instead use Drupal\Component\DependencyInjection\Container

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy created an issue. See original summary.

Gábor Hojtsy’s picture

Gábor Hojtsy’s picture

Status: Needs review » Active
alexpott’s picture

This is the same problem we're trying to resolve in Drupal land. Essentially we don't care about Symfony 4 deprecations in Drupal 8. We do though in Drupal 9.0.0 - that's why when we get this sorted out we file an upstream PR because being able to ignore by version is useful functionality.

Gábor Hojtsy’s picture

Hm, can you show an upstream PR that I can model after? I am not sure what would Symfony need to know? They don't seem to be in the wrong here at all. They deprecated an interface in Symfony 4.x and added another in Symfony 4.x. We are on Symfony 3 but our testing with Symfony 4.x reveals we are not yet compatible with that change and we cannot be.

As per Berdir this needs to be added to Drupal\Tests\Listeners\DeprecationListenerTrait. I don't know how to add it there though, at least that seems to have facilities for verbatim strings, but in this case, the first part is dynamic, depends on the implementing class. This part:

The "Drupal\Component\DependencyInjection\Container" class implements ...

So to cover this in Drupal\Tests\Listeners\DeprecationListenerTrait we may need to extend that class to be able to match messages with regex rather than verbatim strings only.

mikelutz’s picture

While the message is dynamic, it's only used in Drupal\Component\DependencyInjection\Container, and all 17 deprecation failures I see in the symfony 4 thread are all identical. I think we could just add the one message to ignore it for now.

alexpott’s picture

Yeah let's do #6 and add a new section to \Drupal\Tests\Listeners\DeprecationListenerTrait::getSkippedDeprecations()

Something like

      // Deprecations in Symfony 4 for Symfony 5.
      // @todo Remove in Drupal 9.
      'blah'
Gábor Hojtsy’s picture

Lol I did not notice that was the only one. Easier then :)

alexpott’s picture

:( we need to make \Drupal\Tests\Listeners\DeprecationListenerTrait::getSkippedDeprecations() work for unit tests - it's never had to do that before.

I think we might have to do something awful to support it - like use reflection to change the value of \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::$gatheredDeprecations()

mikelutz’s picture

I was just driving myself crazy trying to figure out why these didn't go away when I tried this in the main symfony 4 thread.. :-/

mikelutz’s picture

A good chunk of the remaining functional test failures seem to be due to escaping Constraint Violation messages. The test is looking for A feed named <em class="placeholder">iD5qjReymv</em> already exists. Enter a unique title. and the response contains A feed named &lt;em class=&quot;placeholder&quot;&gt;iD5qjReymv&lt;/em&gt; already exists. Enter a unique title.I'm only starting to dig into why that might be happening, but I thought I would mention it in case it triggered any ideas with anyone who has been working with this more than I have.

Whoops, wrong issue, ignore me.

alexpott’s picture

Yeah that's not pleasant. We need to wrap the Symfony deprecation error handler to do this. But because that has something that detects if it has been replaced we need to put it back again at the end.

catch’s picture

(crosspost with Alex Pott, haven't looked at the latest patch yet).

We can extend Symfony's ResettableContainerInterface and remove the deprecation annotation. This doesn't require any new testing infrastructure.

Absolutely zero core code type hints on this interface, so when we need to actually require Symfony 4.2 or Symfony 5, it should be fine to switch the use statement again to Symfony\Contracts directly (which appears to be brand new from July 2018).

The last submitted patch, 13: 3029197-13.patch, failed testing. View results

catch’s picture

Thinking about Symfony 5 forwards-compatibility. If this patch passes on Symfony 3 (afaict it should), and we're confident no-one type hints on ResettableContainerInterface (no reason why they would), then it might also be enough.

Status: Needs review » Needs work

The last submitted patch, 16: 3029197-15.patch, failed testing. View results

catch’s picture

Status: Needs work » Needs review
FileSize
54.53 KB

With the composer changes this time.

The last submitted patch, 13: 3029197-sf4-13.patch, failed testing. View results

The last submitted patch, 14: 3029197-13-combined.patch, failed testing. View results

Gábor Hojtsy’s picture

Oh! I looked into Symfony 3.4 and it did not have this contract but if that is a separate package for 3.4, then this could also work, assuming nobdy typehints on ResettableInterface yeah.

alexpott’s picture

Here's a patch that makes the skipping work... we might need to do this because they might be something we can't do by including another dependency.

catch’s picture

The problem with #18 is that Symfony\Contracts requires PHP 7.1.3. So it would be fine if we required that, but we do not yet.

Another option - just don't implement either interface!

(another crosspost with alexpott)

alexpott’s picture

I think #24 is a good reason #22 is the way to go - skip SF4->SF5 deprecations for now and concentrate on SF4 and getting feedback for that.

Gábor Hojtsy’s picture

alexpott’s picture

Status: Needs review » Needs work

I think we can proceed with #23. I find it extremely unlikely that anyone is using the interface. Searching popular contrib - no one is using it - http://grep.xnddx.ru/search?text=ResetInterface&filename= so I think it is fine to go with #23. However @Gábor Hojtsy pointed out that we should add an @todo to re add the interface in Drupal 9 / for when we adopt Sf5

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
653 bytes
1.17 KB
alexpott’s picture

Status: Needs review » Reviewed & tested by the community

Yeah done indeed - onwards.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: 3029197-28.patch, failed testing. View results

Gábor Hojtsy’s picture

Status: Needs work » Reviewed & tested by the community

Random media fail. Sending for retest.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: 3029197-28.patch, failed testing. View results

Gábor Hojtsy’s picture

Status: Needs work » Reviewed & tested by the community

Random fail again.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record, +Needs issue summary update

and we're confident no-one type hints on ResettableContainerInterface (no reason why they would),

Searching popular contrib - no one is using it - http://grep.xnddx.ru/search?text=ResetInterface&filename= s

Shouldn't we be searching for ResettableContainerInterface and not ResetInterface?

Also, that site is down now, so can't recheck.

I think we need to confirm no one is using ResettableContainerInterface on the basis of the patch and we also need an issue summary update, as it still talks about adding to the allowed deprecations list.

In addition, we need a change record - this is an API break for anyone type-hinting on that interface in client code.

Gábor Hojtsy’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated IS.

Gábor Hojtsy’s picture

Issue tags: -Needs change record

Added a draft change notice at https://www.drupal.org/node/3036823. I also realized the patch needs updating the phpdoc on reset() since it cannot inherit its method description from the interface anymore.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
1.71 KB
852 bytes

Updated.

larowlan’s picture

I think we still need to grep contrib for ResettableContainerInterface as earlier comments indicate we were looking for the wrong thing

Gábor Hojtsy’s picture

https://www.drupal.org/u/xandeadx maintains http://grep.xnddx.ru/, I reached out if they can relaunch it.

Gábor Hojtsy’s picture

Apparently http://codcontrib.hank.vps-private.net/search?text=ResettableContainerIn... is the same site as per xandeadx. It seems like portfolio_theme has a copy of Drupal core and Symfony, etc. Other than that no uses of that.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

Awesome - we've done due diligence here. Removing it and adding it back again when we have symfony/contracts seems the best solution.

alexpott’s picture

Another reason why this is a fine approach is that contain reset in Symfony land is now a test-only thing - see https://github.com/symfony/symfony/pull/16609

It's tempting to not the follow-up but deprecate \Drupal\Component\DependencyInjection\Container::reset() and remove it in Drupal 9.

larowlan’s picture

Issue summary: View changes
Issue tags: +8.7.0 release notes

I opened #3037826: Theme contains a complete version of core and its dependencies to address portfolio theme including 8.6.9 core and all of vendor

It's tempting to not the follow-up but deprecate \Drupal\Component\DependencyInjection\Container::reset() and remove it in Drupal 9.

+1

Committed 1036f4c and pushed to 8.7.x. Thanks!

Published change record

Added release notes snippet

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

  • larowlan committed 1036f4c on 8.7.x
    Issue #3029197 by catch, Gábor Hojtsy, alexpott, mikelutz: [symfony 5]...

Status: Fixed » Closed (fixed)

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