Service decorates non-existant service when module not installed

Created on 2 July 2022, over 2 years ago
Updated 19 September 2024, 3 months ago

Problem/Motivation

Under certain circumstances when creating a new service with new service decorators you can end up with the error

The service "moduleb.service" has a dependency on a non-existent service "modulea.service".

Presently the only way to solve this problem is to create a Service Provider with the following code:

public function alter(ContainerBuilder $container) {
    if (!$container->hasDefinition('modulea.service')) {
      $container->removeDefinition('moduleb.service');
    }
  }

There are better ways to address this issue. One potential solution is https://www.drupal.org/project/drupal/issues/3111008 ✨ Use native Symfony YamlLoader + Config Needs work because that will allow service.yml files to set decoration_on_invalid to something other than exception (the default value).

This issue is to provide a smaller solution that will hopefully be easier to get passed.

Steps to reproduce

  1. Create a Drupal site. Create and install moduleb.
  2. Create modulea and create a service
  3. Add a service in moduleb that decorates the service from modulea

After those three steps nothing will function.

Proposed resolution

Add support for Symfony's decoration_on_invalid property in Drupal's YamlFileLoader.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 6 hours ago

Created by

πŸ‡¨πŸ‡¦Canada geekygnr Waterloo

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024