Problem/Motivation
In Drupal 11.4, Drupal\update\MailHandler was refactored to use #[AutowireServiceClosure] attributes on its constructor parameters. However, the service definition in update.services.yml was not updated to match — it remains as a bare ~ (null), with no autowire: true directive.
As a result, when the service container attempts to instantiate MailHandler, it passes zero arguments, causing:
ArgumentCountError: Too few arguments to function Drupal\update\MailHandler::__construct(), 0 passed in [container] and exactly 4 expected
Steps to reproduce
- Install Drupal 11.4 (or 11.x-dev).
- Configure update email notifications at /admin/reports/updates/settings — add at least one email address to the "Email addresses to notify" field.
- Trigger instantiation of the Drupal\update\MailHandler service (e.g. by running cron when there are pending updates, or by directly invoking the update.mail_handler service from code).
- Observe the ArgumentCountError: Too few arguments to function Drupal\update\MailHandler::__construct(), 0 passed.
Proposed resolution
Add autowire: true to the MailHandler service definition in update/update.services.yml:
Drupal\update\MailHandler:
autowire: trueThis allows Symfony's dependency injection container to automatically resolve the constructor arguments via the #[AutowireServiceClosure] attributes already present on the class.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3591548
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:
- 3591548-drupalupdatemailhandler-service-missing
changes, plain diff MR !15842
Comments
Comment #3
ltrainComment #4
dalinSounds like a major issue.
For the steps to reproduce, I'd be surprised if there isn't already tests for each one of those things, so do we need a test for some of the steps combined?
Comment #5
smustgrave commentedDefinitely would count as a major
Comment #7
xjmNice find, thanks!
This definitely points to missing test coverage.
Since this is an 11.4.x major regression with a very easy hotfix (and we're tagging a beta soon), I went ahead and committed the hotfix without tests, but let's add those next please. 🙂 Leaving open for that.
Comment #8
xjmThe tests would presumably be needed on
maintoo.Comment #9
smustgrave commentedFor test coverage this only seems to be called from the cron job. Or can we just go straight to the handler and something like
Comment #10
dwwThis is an example of why
Unittests, while fast, aren't always that helpful. 😅 The only coverage we currently have of the email sending isDrupal\Tests\update\Unit\UpdateMailTestwhich of course mocks a bunch of stuff to make a fake container, and only tests that the text coming out ofUpdateHooks::mail()matches what we expect, given some imaginary site status.This bug would really only be seen with a
Functionaltest that was actually trying to do end-to-end testing of a site that was out of date, and seeing what actual email the test site generates.While I appreciate the simplicity, I think #9 is pretty contrived. 😉 I don't believe we do that for any other services.
If we're going to add test coverage for this, I think it should be a Functional test that sets up mock status/history to be out of date, triggers cron, and checks what the email that gets sent looks like.
Drupal\Tests\update\Functional\UpdateMiscTest::testModulePageRunCron()is pretty darn close to that. Could probably be expanded to cover that email is actually being sent as appropriate.Comment #11
smustgrave commentedFully get it agree just wanted to confirm sounds like a plan if no one beats me to it may try next week
Comment #12
xjmSemi-regretting my committing the hotfix without tests now. It was still probably the right decision but the tests are still missing 4 months later. 😅
Comment #14
brandonlira commentedUpdated the MR!15842 and resolved the previous branch/conflict issues.
I also added functional test coverage for the cron update notification path. The test configures an update notification recipient, simulates an available core update, runs cron, and asserts that an update_status_notify email is sent with the expected recipient, subject, and body.
The MR pipeline is now passing and this is ready for review. Please let me know if any adjustments are needed.
Comment #15
smustgrave commentedSince this wasn't really needed for main/12 so tested on my local 11.x instance
I reverted https://git.drupalcode.org/project/drupal/-/commit/32ebf9e0484ce5fb56fa6...
Applied the test and ran and got a failure
Failed asserting that actual size 0 matches expected size 1.
/var/www/html/core/modules/update/tests/src/Functional/UpdateMiscTest.php:207
Not 100% we need the test for main but for 11.x it appears to cover the bug.
Comment #17
catchCommmitted/pushed to main, thanks!
Leaving open for backport after the security release freeze.
Comment #20
catchCherry-picked to 12.0.x, 11.x and 11.5.x, thanks!
Comment #23
catch