Problem/Motivation

`CoreServiceProvider` auto-tags every service implementing `Psr\Log\LoggerAwareInterface` with `logger_aware`. `LoggerAwarePass` then requires every `logger_aware`-tagged service to implement that interface, throwing `InvalidArgumentException` otherwise.

This breaks container build as soon as such a service is decorated by a class that does not itself implement `LoggerAwareInterface` — a usual decoration pattern.

Steps to reproduce

- Have a site on 11.4.3
- HAve it somewhere decorate a logger (in my case used donquixote's excellent exception_log_tree_formatter)
- Update to 11.4.4
- See that every Drush invocation throws:

InvalidArgumentException: Service "Drupal\Core\Command\DrupalConsoleLogger" must implement interface "Psr\Log\LoggerAwareInterface".

Note that the exception names the service ID, not the overriding service class. A fact that gave me debugging headaches and which I fixed too in upcoming patch.

Proposed resolution

- Make LoggerAwarePass only inject those services in the decorator chain that actually implement LoggerAwareInterface.

Abandoned approaches:
- Blessing the current need to have every service decorating LoggerAware implement and decorate that interface. LoggerAware describes deferred setter injection, and is not a contract of that service. (And think of what happens when that logic someday applies to ContainerAware, RequestAware, RouteAware, ...)
- Adding logger_aware to the list of container.behavior_describing_tags. While semantically more correct and maybe reasonable when implementing in the first place, that would change behavior too much and open lots of BC issues.

Remaining tasks

- Review, bikeshed, commit.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

A bug was fixed where decorating services implementing LoggerAwareInterface required the decorator to implement the same interface, with the DI container throwing otherwise.

Issue fork drupal-3612206

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

geek-merlin created an issue. See original summary.

geek-merlin’s picture

Assigned: Unassigned » geek-merlin
Status: Active » Needs review
geek-merlin’s picture

Status: Needs review » Active

Sorry, didn't mean that.

geek-merlin’s picture

Assigned: geek-merlin » Unassigned
Status: Active » Needs review

MR flying in. Used an LLM, but all errors are mine.
MR fixes the issue in my installation and allows me to update to 11.4.4.
Tests are green, test-only changes fail the way expected.

geek-merlin’s picture

Assigned: Unassigned » geek-merlin

Will improve it, but the principle is stable.

geek-merlin’s picture

Status: Needs review » Needs work

Still doing self-review.