Call to undefined method Drupal\attachinline\Asset\LibraryDiscoveryDecorator::destruct

Created on 2 May 2025, 15 days ago

Problem/Motivation

I got this error on Drupal 11.1.6 when execute "drush cex"

 [error]  Error: Call to undefined method Drupal\attachinline\Asset\LibraryDiscoveryDecorator::destruct() in Drupal\Core\DrupalKernel->terminate() (line 691 of /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php) #0 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(314): Drupal\Core\DrupalKernel->terminate()
#1 [internal function]: Drush\Boot\DrupalBoot8->terminate()
#2 {main}.
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @DimaS11
  • Merge request !11Update file LibraryDiscoveryDecorator.php → (Closed) created by DimaS11
  • Pipeline finished with Success
    15 days ago
    Total: 140s
    #487210
  • 🇨🇦Canada gapple

    This raises a couple issues from Drupal core:
    - The library.discovery service is now implicitly expected to have the additional methods from CacheCollectorInterface (e.g. clear() is also called from ModuleInstaller), even though LibraryDiscoveryInterface doesn't include them.
    - destruct() is being called on a decorator service which does not have the needs_destruction tag - because the decorated service does: 🐛 Container compile crash when a service decorates a destructable service Needs work

    Symfony's documentation doesn't include the needs_destruction tag in the ones it lists as being copied from the decorated service to the decorator (https://symfony.com/doc/current/service_container/service_decoration.html), but \Drupal\Core\DependencyInjection\Compiler\RegisterServicesForDestructionPass::process() applies the kernel.destructable_services parameter to the service, which appears tied to the service name and not the actual implementing class (and so is called on the decorator by \Drupal\Core\DrupalKernel::terminate()).

    ----

    Service decorators should not extend their decorated class.

    Decoration allows stacking alterations to the public interface of the original class, without concern for if the next layer of the stack is another decorator or the original service - or even if the original service has been swapped for a different implementation. However, if a decorator extends the original class then it will not proxy calls properly to the next layer of the stack.

    The quickest change is to add proxy methods for just the additional ones used on the library discovery service (clear() and destruct()), but to prevent potential other issues if service consumers use the methods of LibraryDiscoveryCollector and not just LibraryDiscoverInterface, the decorator should implement and proxy all the methods of CacheCollectorInterface and DestructableInterface. This would also prevent problems if the service is passed somewhere that types against those interfaces.

  • 🇨🇦Canada gapple

    Fixed, but I forgot to add the issue # to the commit.

Production build 0.71.5 2024