Problem/Motivation
During a recent deployment, we saw errors in the logs:
TypeError: Drupal\trash\EventSubscriber\TrashConfigSubscriber::__construct():
Argument #6 ($loggerFactory) must be of type Drupal\Core\Logger\LoggerChannelFactoryInterface, Drupal\Core\Action\ActionManager given
At first, we thought the problem was that Commit ed599e43 added a parameter to TrashConfigSubscriber but neglected to update trash.services.yml. Further analysis showed that autowiring should have handled that, so the problem is that the service container was not rebuilt during the deployment.
This may have been caused by a delay between updating the code and updating the database, but it can also happen when deploying with drush updatedb --no-cache-clear. I am not sure how common that is, but the option is there and some site owners will use it in order to avoid clearing caches unnecessarily.
This problem is temporary: as soon as the container is rebuilt, for whatever reason, it goes away. Fixing this issue should help anyone who uses that option and has not yet updated this module to 3.0.35+.
Steps to reproduce
- Install Trash 3.0.29 on a Drupal 10.3+ site and enable it for at least one entity type (e.g. Content).
- Update the code to 3.0.35:
composer require drupal/trash:3.0.35 - Run
drush updatedb --no-cache-clear. It reports "No pending updates." - Visit the Trash settings page. It fails with an error from one of several classes whose constructors changed between 3.0.29 and 3.0.35, for example:
ArgumentCountError: Too few arguments to function Drupal\trash\TrashEntityPurger::__construct(), 6 passed ... and exactly 7 expected - Alternatively, save
trash.settingsfrom the command line:
drush cset trash.settings auto_purge.enabled 1 -y
This fails in the config subscriber:
TypeError: Drupal\trash\EventSubscriber\TrashConfigSubscriber::__construct(): Argument #6 ($loggerFactory) must be of type Drupal\Core\Logger\LoggerChannelFactoryInterface, Drupal\Core\Action\ActionManager given
Proposed resolution
- Add a post-update function that rebuilds the service container. Testing shows that an empty post-update function does not trigger a rebuild with
drush updatedb --no-cache-clear. - Remove explicit parameters from
trash.services.ymlto avoid confusion. - Pass a logger object instead of the logger factory, to follow Drupal standards.
Remaining tasks
User interface changes
None
API changes
The trash.config_subscriber service expects a logger object, not the logger factory.
Data model changes
None
Issue fork trash-3632459
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
benjifisherI worked with Claude code on this issue. I reviewed the code changes, and they are the same things I would have done on my own. I wrote the issue summary myself, except that Claude drafted the steps to reproduce. I tested those steps and the fix (Drupal 10.6.15).
Regarding the 3 items in the proposed resolution:
Comment #4
clairero commentedBefore the patch: I followed the steps to reproduce and got the same issue.
[success] No pending updates.ArgumentCountError: Too few arguments to function Drupal\trash\TrashEntityPurger::__construct(), 6 passed ... and exactly 7 expected
TypeError: Drupal\trash\EventSubscriber\TrashConfigSubscriber::__construct(): Argument #6 ($loggerFactory) must be of type Drupal\Core\Logger\LoggerChannelFactoryInterface, Drupal\Core\Action\ActionManager given
After the patch:
drush updatedb --no-cache-clearnow finds the new post-update:Running it rebuilds the service container, so the stale constructor arguments from the old container are gone. After the update:
The site loads normally and the Trash settings page works.
drush cset trash.settings auto_purge.enabled 1 -ysaves without errors.Removing the explicit arguments from trash.services.yml and injecting a logger channel instead of the logger factory also looks good. It follows Drupal conventions and should make this kind of mismatch less likely in the future.
Marking as RTBC.
Comment #5
clairero commentedComment #10
amateescu commentedLooks great! Merged the 3.x MR and ported it to 3.1.x as well, thanks!