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
Comment | File | Size | Author |
---|---|---|---|
#37 | interdiff.txt | 852 bytes | Gábor Hojtsy |
#37 | 3029197-37.patch | 1.71 KB | Gábor Hojtsy |
#28 | 3029197-28.patch | 1.17 KB | Gábor Hojtsy |
#28 | interdiff.txt | 653 bytes | Gábor Hojtsy |
#23 | 3029197-22.patch | 951 bytes | catch |
Comments
Comment #2
Gábor HojtsyComment #3
Gábor HojtsyComment #4
alexpottThis 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.
Comment #5
Gábor HojtsyHm, 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.
Comment #6
mikelutzWhile 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.
Comment #7
alexpottYeah let's do #6 and add a new section to \Drupal\Tests\Listeners\DeprecationListenerTrait::getSkippedDeprecations()
Something like
Comment #8
Gábor HojtsyLol I did not notice that was the only one. Easier then :)
Comment #10
alexpott:( 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()
Comment #11
mikelutzI 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.. :-/
Comment #12
mikelutzA good chunk of the remaining functional test failures seem to be due to escaping Constraint Violation messages. The test is looking forA feed named <em class="placeholder">iD5qjReymv</em> already exists. Enter a unique title.
and the response containsA feed named <em class="placeholder">iD5qjReymv</em> 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.
Comment #13
alexpottYeah 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.
Comment #14
catch(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).
Comment #16
catchThinking 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.
Comment #18
catchWith the composer changes this time.
Comment #21
Gábor HojtsyOh! 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.
Comment #22
alexpottHere'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.
Comment #23
catchThe 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)
Comment #24
Gábor Hojtsy#3030485: [Symfony 5] The "Drupal\Core\Validation\TranslatorInterface" interface extends "Symfony\Component\Translation\TranslatorInterface" that is deprecated since Symfony 4.2, use Symfony\Contracts\Translation\TranslatorInterface instead. is another fail on #2976394: Allow Symfony 4.4 to be installed in Drupal 8 that is a very similar problem in requiring one of the constraints classes.
Comment #25
alexpottI 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.
Comment #26
Gábor Hojtsy#3030494: [Twig 3] The "Drupal\Core\Template\Loader\StringLoader" class implements "Twig_ExistsLoaderInterface" and "Twig_SourceContextLoaderInterface" that are deprecated since 1.12 and 1.27 (to be removed in 3.0). has the same problem with needing the phpunit listener, which is yet one more +1 for #22.
Comment #27
alexpottI 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
Comment #28
Gábor HojtsyCreated #3032605: [symfony 4] Drupal\Component\DependencyInjection\Container should implement Symfony\Contracts\Service\ResetInterface as postponed. Added @todo. This looks like its done then @alexpott? :)
Comment #29
alexpottYeah done indeed - onwards.
Comment #31
Gábor HojtsyRandom media fail. Sending for retest.
Comment #33
Gábor HojtsyRandom fail again.
Comment #34
larowlanShouldn'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.
Comment #35
Gábor HojtsyUpdated IS.
Comment #36
Gábor HojtsyAdded 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.
Comment #37
Gábor HojtsyUpdated.
Comment #38
larowlanI think we still need to grep contrib for ResettableContainerInterface as earlier comments indicate we were looking for the wrong thing
Comment #39
Gábor Hojtsyhttps://www.drupal.org/u/xandeadx maintains http://grep.xnddx.ru/, I reached out if they can relaunch it.
Comment #40
Gábor HojtsyApparently 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.
Comment #41
alexpottAwesome - we've done due diligence here. Removing it and adding it back again when we have symfony/contracts seems the best solution.
Comment #42
alexpottAnother 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.
Comment #43
larowlanI 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
+1
Committed 1036f4c and pushed to 8.7.x. Thanks!
Published change record
Added release notes snippet
Comment #44
larowlan