If notifications.email is a string, an error occurs

Created on 12 April 2023, about 1 year ago
Updated 26 March 2024, 3 months ago

Problem/Motivation

If for some reason, the notifications.email value is a string, it will produce an error on the update settings page.

Steps to reproduce

  1. drush -y cex
  2. Edit update.settings.yml and change notifications.email to a string. It is an array after a fresh install of Standard
  3. drush -y cim
  4. Go to admin/reports/updates/settings
The website encountered an unexpected error. Please try again later.
TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 92 of core/modules/update/src/UpdateSettingsForm.php).
implode('
', NULL) (Line: 92)
Drupal\update\UpdateSettingsForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 534)
Drupal\Core\Form\FormBuilder->retrieveForm('update_settings', Object) (Line: 281)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 68)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Change '#default_value' => implode("\n", $notification_emails), for '#default_value' => isset($notification_emails) ? implode("\n", $notification_emails) : NULL,

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Update 

Last updated about 5 hours ago

  • Maintained by
  • 🇺🇸United States @tedbow
  • 🇺🇸United States @dww
Created by

🇨🇦Canada FranckyLFS Montreal

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

Merge Requests

Comments & Activities

  • Issue created by @FranckyLFS
  • 🇺🇸United States cilefen

    Thank you for the patch and for the stack trace.

    This seems to be an unusual situation. I don't understand how $notification_emails could be unset at this line because just above this section it is set as:

    $notification_emails = $config->get('notification.emails');
    

    I think $notification_emails could be null here, but only if there is something wrong with the site configuration. notification.emails is set to an empty array on install and it is part of the update module schema. What does a var_dump of $notification_emails show?

    I think the steps to reproduce need some refinement.

  • Status changed to Postponed: needs info about 1 year ago
  • 🇺🇸United States kwiseman

    I was having the same issue. Uninstalling and then reinstalling Update Manager fixed it. The site is using Drupal 9.5.8 and PHP 8.1.13.

  • 🇺🇦Ukraine goodboy Kharkiv, Ukraine

    I am having the same issue.
    $notification_emails is NULL.

  • 🇱🇻Latvia Phonoman

    The patch looks good and makes sense to include it in the core, IMO.
    Calling a function that can break the page on unchecked variables is much worse than just adding a normal safety check. Perhaps the missing values come from old installs/configurations and/or migrations when it wasn't necessary. Reinstalling + importing configs will still remove the initially installed empty array when one wants to keep the original settings.

    You can also just manually add the missing value in update.settings.yml and import configs to resolve the issue as well, but better safe than sorry?

    notification:
      emails: {  }
  • 🇺🇸United States texas-bronius

    The suggested patch (explained in Proposed Resolution) worked for me, too. This D9 site on php 7.4 is being run on php 8.1.22 (8.0.0 removed the legacy param order, per changelog on php.net; info thanks to this smart guy)

  • Status changed to Active 9 months ago
  • 🇳🇿New Zealand quietone New Zealand

    I found a way to reproduce this which I added to the IS.

    Turns out that notification.emails can be saved as string, an array or NULL. And it doesn't validate the email address either.

    I wonder if there are duplicates of this.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    32:34
    31:46
    Running
  • Status changed to Needs review 5 months ago
  • 🇺🇸United States SocialNicheGuru

    Is this a problem in D10.2 or D11?

  • Status changed to Active 5 months ago
  • 🇺🇸United States smustgrave

    #9 seems @quietone was able to reproduce in 11.x branch.

  • 🇪🇸Spain Juanjol Navarra

    Still a problem in D10.2, attached patch with 10.2 version compatibility.

  • Status changed to Needs review 4 months ago
  • Status changed to Needs work 4 months ago
  • The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • First commit to issue fork.
  • Merge request !6804Resolve #3353778 "Argument type" → (Open) created by sumit-k
  • Status changed to Needs review 4 months ago
  • 🇮🇳India sumit-k

    Raised MR !6804 of patch #13.

  • Pipeline finished with Failed
    4 months ago
    Total: 185s
    #105609
  • Status changed to Needs work 4 months ago
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Pipeline finished with Success
    4 months ago
    Total: 472s
    #105662
  • Status changed to Needs review 4 months ago
  • 🇮🇳India sumit-k

    Fixed core commit check issues. Changing status to Need Review.

  • Status changed to Needs work 4 months ago
  • 🇺🇸United States smustgrave

    Will need test coverage since it caused a fatal error.

Production build 0.69.0 2024