Exception thrown when unblocking a user via drush

Created on 19 April 2023, over 1 year ago
Updated 5 June 2023, over 1 year ago

When attempting to unblock a user via drush an exception is thrown.

Steps to reproduce:
- Fresh install of Drupal 9.5.9
- Create a new user without an email address (yes, Drupal does let you do this !)
- block the user via drush ('drush user:block ')
- unblock the user via drush ('drush user:unblock ')

The following exception is then thrown:

[error] TypeError: Drupal\Core\Mail\Plugin\Mail\PhpMail::doMail(): Argument #1 ($to) must be of type string, null given, called in /app/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 118 in Drupal\Core\Mail\Plugin\Mail\PhpMail->doMail() (line 162 of /app/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php) #0 /app/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php(118):

πŸ› Bug report
Status

Needs work

Version

9.5

Component
MailΒ  β†’

Last updated 21 days ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom DuttonMa

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

Comments & Activities

  • Issue created by @DuttonMa
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    The one-line error is not enough go go on. We need more of a stack trace to take this on as a bug report.

  • Status changed to Downport over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom DuttonMa

    Patch attached to resolve this issue

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    We still need steps to reproduce to understand why the "to" field is empty.

  • last update over 1 year ago
    30,322 pass
  • πŸ‡¬πŸ‡§United Kingdom DuttonMa

    Steps to reproduce:
    - Fresh install of Drupal 9.5.9
    - Create a new user without an email address (yes, Drupal does let you do this !)
    - block the user via drush ('drush user:block

    - unblock the user via drush ('drush user:unblock ')

    At this point the following TypeError is thrown:

    TypeError: Drupal\Core\Mail\Plugin\Mail\PhpMail::doMail(): Argument #1 ($to) must be of type string, null given, called in /app/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 118 in /app/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 162 #0 /app/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php(118): Drupal\Core\Mail\Plugin\Mail\PhpMail->doMail(NULL, 'Account details...', 'test4,\n\nYour ac...', 'MIME-Version: 1...', '-fadmin@example...')
    #1 /app/web/core/lib/Drupal/Core/Mail/MailManager.php(307): Drupal\Core\Mail\Plugin\Mail\PhpMail->mail(Array)
    #2 /app/web/core/lib/Drupal/Core/Mail/MailManager.php(180): Drupal\Core\Mail\MailManager->doMail('user', 'status_activate...', NULL, 'en', Array, 'admin@example.c...', true)
    #3 /app/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}()
    #4 /app/web/core/lib/Drupal/Core/Mail/MailManager.php(181): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #5 /app/web/core/modules/user/user.module(1069): Drupal\Core\Mail\MailManager->mail('user', 'status_activate...', NULL, 'en', Array, 'admin@example.c...')
    #6 /app/web/core/modules/user/src/Entity/User.php(139): _user_mail_notify('status_activate...', Object(Drupal\user\Entity\User))
    #7 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(597): Drupal\user\Entity\User->postSave(Object(Drupal\user\UserStorage), true)
    #8 /app/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(781): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\user\Entity\User), true)
    #9 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(523): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\user\Entity\User), true)
    #10 /app/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(804): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\user\Entity\User))
    #11 /app/web/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\user\Entity\User))
    #12 /app/vendor/drush/drush/src/Drupal/Commands/core/UserCommands.php(159): Drupal\Core\Entity\EntityBase->save()
    #13 [internal function]: Drush\Drupal\Commands\core\UserCommands->unblock('test4', Array)
    #14 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
    #15 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #16 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #17 /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(390): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #18 /app/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #19 /app/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #20 /app/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #21 /app/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #22 /app/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #23 /app/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
    #24 /app/vendor/drush/drush/drush.php(77): Drush\Runtime\Runtime->run(Array)
    #25 /app/vendor/drush/drush/drush(4): require('/app/vendor/dru...')
    #26 /app/vendor/bin/drush(120): include('/app/vendor/dru...')
    #27 {main}

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Understood. That information would be better placed in the issue summary.

    What kind of email is Drupal sending in these cases? Is there really no β€œto” value? What even attempt sending the email?

  • πŸ‡¬πŸ‡§United Kingdom DuttonMa
  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    30,334 pass
  • πŸ‡¬πŸ‡§United Kingdom DuttonMa

    I have put those 'steps to reproduce' in the issue summary as suggested.

    In this case no email is sent from Drupal, but an attempt is made to send one. I notice that when you create a user without an email address through the admin screens, Drupal is clever enough to not attempt sending the email even if you click 'notify user' and tells you so. Perhaps the best solution would be to not even attempt to send the email when unblocking the user via drush as well ?

    I attach a new patch to fix this issue at the PHP mail level as there was a problem with the first one.

  • Status changed to Needs work over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    I agree this should be fixed in drupal, not in drush, but I don't think the fix in #8 is the right one, this is too late in the chain. The mail should not be attempted to be sent instead of sending it to an empty string.

  • πŸ‡¬πŸ‡§United Kingdom DuttonMa

    Yes that's what I thought too, the fix in #8 πŸ› Exception thrown when unblocking a user via drush Needs work is a temporary one just to stop the exception - I'll work on a better fix further up in the logic

  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    30,334 pass
  • πŸ‡¬πŸ‡§United Kingdom DuttonMa

    Here is a better patch that doesn't try to send the notification email if the user doesn't have an email address

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Did not test

    Sending to NW for the tests.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Environment: PHP 8.1 & MySQL 5.7 updated deps
    last update about 1 year ago
    30,341 pass
Production build 0.71.5 2024