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
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
Comment #3
geek-merlinComment #4
geek-merlinSorry, didn't mean that.
Comment #5
geek-merlinMR 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.
Comment #6
geek-merlinWill improve it, but the principle is stable.
Comment #7
geek-merlinStill doing self-review.