Problem/Motivation

I receive a PHP Error with the latest release 2.0.2: TypeError: _user_registrationpassword_mail_notify(): Return value must be of type array, bool returned in _user_registrationpassword_mail_notify()

Steps to reproduce

Register as a new user which sends an email.

If I revert the version to 2.0.1 the problem does not exits. If I look at the changes in de last version (2.0.2) the function _user_registrationpassword_mail_notify() now expects an array. When I look at the Kernel Test testUserRegistrationMailsSent() its being tested for a boolean.

Command icon 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

coretex created an issue. See original summary.

juandels3’s picture

The same error happened to me. When downgrading to version 2.0.1 the error is not reproduced.

dercheffe’s picture

Priority: Normal » Major

Same Issue here. IMO this is a major or even critical bug because it breaks user experience massively

megakeegman’s picture

Glad to find this issue, as I was also about to report it. It doesn't look like there is any reason this function needs to return an array, since the results are not actually used for anything besides to check if the array returned is empty. Additionally, I can see where some of the confusion is coming from. The mail function, run on line 622 of the .module, is documented to return a bool. However, the implementation that I am seeing from my current site's mailer, which is called in the MailManagerReplacement class of the symfony_mailer contrib module, returns an array. So there seems to be a lot of confusion even deeper around whether or not we should be dealing with an array or a bool. I am not sure yet where exactly this confusion stems from, whether this a core change that contrib modules haven't caught up with or whether there are just a few implementations doing it wrong. My best guess so far is that everything should be moving in the direction of the mail function returning a bool, and then any of the code that does anything with the result of the mail function should be updated accordingly. Of course ensuring that our mailers are implementing the mail function correctly. There is also the possibility that the mail function is just documented incorrectly. If anyone has any background knowledge on this, that would be great.

megakeegman’s picture

For what it's worth, the MailInterface class in Drupal core hasn't been touched for 3 years, and indicates that the mail function should return a bool, see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

as well as the core symfony mailer implementation https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

And indeed, the relevant issue in symfony_mailer (contrib, not what's in core) about its implementation returning a value of the wrong type (array): https://www.drupal.org/project/symfony_mailer/issues/3400070

So yeah... Those are the clues we have to work with.

The spaghetti coder in me says handle both scenarios by having user_registrationpassword_mail_notify return either $mail or $mail['result'] depending on whether $mail is an array or a boolean. The module maintainer in me says don't spaghetti code. But either way have the return value of user_registrationpassword_mail_notify be a boolean, not an array. and wherever the result of this function is stored, update any logic to that touches it to handle the boolean as well.

sadix_selah’s picture

I have a quick because I don't enaough time to think it through :

$mail = \Drupal::service('plugin.manager.mail')->mail('user_registrationpassword', $op, $account->getEmail(), $langcode, $params, $site_mail);
//$output = $mail['result'] ?? [];
$output = $mail['result'] ? $mail : [];

megakeegman’s picture

Unfortunately, that won't work in the cases where $mail contains a boolean, which I think it should. But I'd really like to hear a maintainers thoughts on how they want to handle this, and if there is any history behind this.

megakeegman’s picture

StatusFileSize
new1.68 KB

I created a simple patch, which should work for anyone using a mailer that incorrectly implements the mail function, like the symfony_mailer contrib module. If you are using another mailer that correctly implements the mail function, and the mail function returns a boolean as per the Drupal core mail interface, then this patch is not for you.

With that being said, it should be pretty easy to re-patch for that, and I think that patch should also exist.

If someone wants or needs this, I think you just need to change

$output = $mail['result'] ?? FALSE;

to

$output = $mail ?? FALSE;

Unfortunately I don't have a list of which mailer modules do what.

jeremyskinner’s picture

We've also run into this issue, which is causing our CI to fail. We've rolled back to 2.0.1 for now. Any chance of getting a new release with a fix for this as it breaks on all versions of Drupal 10 out of the box with no custom mail modules installed.

megakeegman’s picture

Priority: Major » Critical

grimreaper made their first commit to this issue’s fork.

grimreaper’s picture

Assigned: Unassigned » grimreaper

grimreaper’s picture

Version: 2.0.2 » 2.0.x-dev
Assigned: grimreaper » Unassigned
Status: Active » Needs review
StatusFileSize
new3.57 KB

Here is the patch from MR for Composer usage.

I got to the same conclusions of @megakeegman.

MR is a slightly more advanced to handle cases.

Thanks for the review.

noah’s picture

We're using Mailgun to send email, and we're seeing the problem both with and without the patch because the Mailgun module returns Mailgun\Model\Message\SendResponse rather than an array or a boolean. I looked for documentation to see if there's a “right” type for $return['result'], but couldn't find anything. I did find that the email_contact module dealt with the same issue just by checking if $return['result'] is empty rather than expecting a specific type:

https://www.drupal.org/project/email_contact/issues/3468210

Would that be a reasonable option here?

umit’s picture

+1 The same problem was observed on our sites

noah’s picture

StatusFileSize
new4.35 KB

I've updated the MR to check if $mail['return'] is empty, rather than expecting a specific type, which should make it more flexible and compatible with, e.g. the Mailgun module. Updated patch attached.

gorkagr’s picture

Same error making the site a bit unusable for us (at least is local and we did not deploy it yet).

MR works fine.
Best

gorkagr’s picture

Status: Needs review » Reviewed & tested by the community
thirstysix’s picture

#17 works fine with D10.3.x

muaz7731’s picture

+1 for RTBC patch #17

ankitv18’s picture

Status: Reviewed & tested by the community » Needs work

Left a comment ~~ moving into NW

vladimiraus made their first commit to this issue’s fork.

vladimiraus’s picture

Status: Needs work » Needs review

Based on mail() function documentation, it only can return an array.
Please review.

megakeegman’s picture

I did not recognize that there was a difference between MailManagerInterface and MailInterface: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Mail%21Ma...

So the mail function on MailInterface returns a bool, while the one on MailManagerInterface returns an array. And MailInterface->mail() "sends message composed by MailManagerInterface->mail()"

coretex’s picture

The issue is fixed with the last MR changes from VladimirAus.

andrew answer’s picture

StatusFileSize
new478 bytes

Hi,

I debugged the problem and find out that Drupal return 1 (just 1) from mail() function, so I replace null coalescing operator with its equivalent isset() according to PHP documentation, and add array [] to the first option (see patch).

The bug is gone. D10.3.10, user_registrationpassword 2.0.2.

elusivemind’s picture

I think this will work. But since the calling function on 339 doesn't care about a return value and 554 is just looking for a value, should the return of the function be a bool and the returns refactored accordingly? Happy to do it, but thought it may be a better way to go.

elusivemind’s picture

Patch #17 worked for me on v2.0.2 and drupal 11.0.9

It is also, in my opinion, the correct way to fix this. Verified working.

ron collins’s picture

The patch in #17 is working for m as well.

ron collins’s picture

Status: Needs review » Reviewed & tested by the community
phannphong’s picture

The patch #17 works like a charm. Thank you!

coretex’s picture

A lot of people are saying patch from 17 works and different people have commited changes as patches and the merge request. Which one will be merged? Can one of the module maintainers merge this and make a new release?

oily made their first commit to this issue’s fork.

oily’s picture

Fixed PHPCS.

oily’s picture

Status: Reviewed & tested by the community » Needs work

There are unresolved comments in the MR. These need to be resolved before this can be reviewed.

The edits to the gitlab pipeline file should probably be done in a follow-up. It is not clear what relationship they have to the issue.

shivam_tiwari made their first commit to this issue’s fork.

oily’s picture

@shivam_tiwari I have added 2 more comments. Seems you made 2x changes that were unnecessary, I suggest you revert those changes. Then PHPCS should pass. Once that happens the pipeline will progress to the tests and we can see if the tests are passing.

shivam_tiwari’s picture

@oily Sorry for that, Firstly I updated MR according to the comments on the MR. Now I reverted the code according to you. Thanks for your quick response.

oily’s picture

@shivam_tiwari Good work!

I think there is one unresolved comment left now? The comment concerning the .module file. I am not sure the suggested code is exactly right. Needs work. And one test is failing. The test describes the failure quite well.

Once these 2 things are done can change to 'Needs review'.

shivam_tiwari’s picture

I worked on .module file and tested it. Resolved last comment also, updated code is working fine only phpunit test is failing so need to work on this only.

transmitter’s picture

I believe I've got the same problem on D11 with Drupal Symfony Mailer enabled.
When I try to apply the patch (any of the 3 here, #17 specifically) I get:

Downloading https://www.drupal.org/files/issues/2024-09-03/user_registrationpassword-3467248-17.patch
patch '-p1' --no-backup-if-mismatch -d '/home/user/domain.com/web/core' < '/tmp/680125a5eebaa.patch'
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d '/home/user/domain.com/web/core' < '/tmp/680125a5eebaa.patch'
can't find file to patch at input line 15

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:
--------------------------

|From c05fdcb4a7750494ae48806011f203b9cc6af59a Mon Sep 17 00:00:00 2001
|From: Florent Torregrosa <florent.torregrosa@gmail.com>
|Date: Thu, 22 Aug 2024 23:17:18 +0200
|Subject: [PATCH 1/3] Issue #3467248 by megakeegman, grimreaper, coretex,
| sadix_selah: TypeError: Return value must be of type array, bool returned
|
|---
| user_registrationpassword.module | 15 +++++++--------
| 1 file changed, 7 insertions(+), 8 deletions(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index af83384..3b49808 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------

File to patch: 

Skip this patch? [y] 

Skipping patch.

3 out of 3 hunks ignored


can't find file to patch at input line 72

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:
--------------------------

|-- 
|GitLab
|
|
|From ee881b01a3e1ff09a07ae1fed091ea4cb7eb465e Mon Sep 17 00:00:00 2001
|From: Florent Torregrosa <florent.torregrosa@gmail.com>
|Date: Thu, 22 Aug 2024 23:18:20 +0200
|Subject: [PATCH 2/3] Issue #3467248 by megakeegman, grimreaper, coretex,
| sadix_selah: TypeError: Return value must be of type array, bool returned
|
|---
| user_registrationpassword.module | 8 +++++++-
| 1 file changed, 7 insertions(+), 1 deletion(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index 3b49808..5734785 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------

File to patch: 

Skip this patch? [y] 

Skipping patch.

1 out of 1 hunk ignored


can't find file to patch at input line 105

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:
--------------------------

|-- 
|GitLab
|
|
|From 0a6919813e9a0d3ade6e063f5125dd667ea215d7 Mon Sep 17 00:00:00 2001
|From: noah-st-amand <noah@tookish.net>
|Date: Tue, 3 Sep 2024 17:12:30 -0400
|Subject: [PATCH 3/3] Make notification return check compatible with
| third-party mail systems
|
|---
| user_registrationpassword.module | 2 +-
| 1 file changed, 1 insertion(+), 1 deletion(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index 5734785..b14dbeb 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------

File to patch: 

Skip this patch? [y] 

Skipping patch.

1 out of 1 hunk ignored


patch '-p0' --no-backup-if-mismatch -d '/home/user/domain.com/web/core' < '/tmp/680125a5eebaa.patch'
Executing command (CWD): patch '-p0' --no-backup-if-mismatch -d '/home/user/domain.com/web/core' < '/tmp/680125a5eebaa.patch'
can't find file to patch at input line 15

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:
--------------------------

|From c05fdcb4a7750494ae48806011f203b9cc6af59a Mon Sep 17 00:00:00 2001
|From: Florent Torregrosa <florent.torregrosa@gmail.com>
|Date: Thu, 22 Aug 2024 23:17:18 +0200
|Subject: [PATCH 1/3] Issue #3467248 by megakeegman, grimreaper, coretex,
| sadix_selah: TypeError: Return value must be of type array, bool returned
|
|---
| user_registrationpassword.module | 15 +++++++--------
| 1 file changed, 7 insertions(+), 8 deletions(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index af83384..3b49808 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------

File to patch: 

Skip this patch? [y] 

Skipping patch.

3 out of 3 hunks ignored


can't find file to patch at input line 72

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:
--------------------------

|-- 
|GitLab
|
|
|From ee881b01a3e1ff09a07ae1fed091ea4cb7eb465e Mon Sep 17 00:00:00 2001
|From: Florent Torregrosa <florent.torregrosa@gmail.com>
|Date: Thu, 22 Aug 2024 23:18:20 +0200
|Subject: [PATCH 2/3] Issue #3467248 by megakeegman, grimreaper, coretex,
| sadix_selah: TypeError: Return value must be of type array, bool returned
|
|---
| user_registrationpassword.module | 8 +++++++-
| 1 file changed, 7 insertions(+), 1 deletion(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index 3b49808..5734785 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------

File to patch: 

Skip this patch? [y] 

Skipping patch.

1 out of 1 hunk ignored


can't find file to patch at input line 105

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:
--------------------------

|-- 
|GitLab
|
|
|From 0a6919813e9a0d3ade6e063f5125dd667ea215d7 Mon Sep 17 00:00:00 2001
|From: noah-st-amand <noah@tookish.net>
|Date: Tue, 3 Sep 2024 17:12:30 -0400
|Subject: [PATCH 3/3] Make notification return check compatible with
| third-party mail systems
|
|---
| user_registrationpassword.module | 2 +-
| 1 file changed, 1 insertion(+), 1 deletion(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index 5734785..b14dbeb 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------

File to patch: 

Skip this patch? [y] 

Skipping patch.

1 out of 1 hunk ignored


patch '-p2' --no-backup-if-mismatch -d '/home/user/domain.com/web/core' < '/tmp/680125a5eebaa.patch'
Executing command (CWD): patch '-p2' --no-backup-if-mismatch -d '/home/user/domain.com/web/core' < '/tmp/680125a5eebaa.patch'
can't find file to patch at input line 15

Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|From c05fdcb4a7750494ae48806011f203b9cc6af59a Mon Sep 17 00:00:00 2001
|From: Florent Torregrosa <florent.torregrosa@gmail.com>
|Date: Thu, 22 Aug 2024 23:17:18 +0200
|Subject: [PATCH 1/3] Issue #3467248 by megakeegman, grimreaper, coretex,
| sadix_selah: TypeError: Return value must be of type array, bool returned
|
|---
| user_registrationpassword.module | 15 +++++++--------
| 1 file changed, 7 insertions(+), 8 deletions(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index af83384..3b49808 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.
3 out of 3 hunks ignored
can't find file to patch at input line 72
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|-- 
|GitLab
|
|
|From ee881b01a3e1ff09a07ae1fed091ea4cb7eb465e Mon Sep 17 00:00:00 2001
|From: Florent Torregrosa <florent.torregrosa@gmail.com>
|Date: Thu, 22 Aug 2024 23:18:20 +0200
|Subject: [PATCH 2/3] Issue #3467248 by megakeegman, grimreaper, coretex,
| sadix_selah: TypeError: Return value must be of type array, bool returned
|
|---
| user_registrationpassword.module | 8 +++++++-
| 1 file changed, 7 insertions(+), 1 deletion(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index 3b49808..5734785 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 105
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|-- 
|GitLab
|
|
|From 0a6919813e9a0d3ade6e063f5125dd667ea215d7 Mon Sep 17 00:00:00 2001
|From: noah-st-amand <noah@tookish.net>
|Date: Tue, 3 Sep 2024 17:12:30 -0400
|Subject: [PATCH 3/3] Make notification return check compatible with
| third-party mail systems
|
|---
| user_registrationpassword.module | 2 +-
| 1 file changed, 1 insertion(+), 1 deletion(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index 5734785..b14dbeb 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

1 out of 1 hunk ignored


patch '-p4' --no-backup-if-mismatch -d '/home/user/domain.com/web/core' < '/tmp/680125a5eebaa.patch'
Executing command (CWD): patch '-p4' --no-backup-if-mismatch -d '/home/user/domain.com/web/core' < '/tmp/680125a5eebaa.patch'
can't find file to patch at input line 15

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:
--------------------------

|From c05fdcb4a7750494ae48806011f203b9cc6af59a Mon Sep 17 00:00:00 2001
|From: Florent Torregrosa <florent.torregrosa@gmail.com>
|Date: Thu, 22 Aug 2024 23:17:18 +0200
|Subject: [PATCH 1/3] Issue #3467248 by megakeegman, grimreaper, coretex,
| sadix_selah: TypeError: Return value must be of type array, bool returned
|
|---
| user_registrationpassword.module | 15 +++++++--------
| 1 file changed, 7 insertions(+), 8 deletions(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index af83384..3b49808 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------

File to patch: 

Skip this patch? [y] 
Skipping patch.
3 out of 3 hunks ignored
can't find file to patch at input line 72
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|-- 
|GitLab
|
|
|From ee881b01a3e1ff09a07ae1fed091ea4cb7eb465e Mon Sep 17 00:00:00 2001
|From: Florent Torregrosa <florent.torregrosa@gmail.com>
|Date: Thu, 22 Aug 2024 23:18:20 +0200
|Subject: [PATCH 2/3] Issue #3467248 by megakeegman, grimreaper, coretex,
| sadix_selah: TypeError: Return value must be of type array, bool returned
|
|---
| user_registrationpassword.module | 8 +++++++-
| 1 file changed, 7 insertions(+), 1 deletion(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index 3b49808..5734785 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 105
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|-- 
|GitLab
|
|
|From 0a6919813e9a0d3ade6e063f5125dd667ea215d7 Mon Sep 17 00:00:00 2001
|From: noah-st-amand <noah@tookish.net>
|Date: Tue, 3 Sep 2024 17:12:30 -0400
|Subject: [PATCH 3/3] Make notification return check compatible with
| third-party mail systems
|
|---
| user_registrationpassword.module | 2 +-
| 1 file changed, 1 insertion(+), 1 deletion(-)
|
|diff --git a/user_registrationpassword.module b/user_registrationpassword.module
|index 5734785..b14dbeb 100644
|--- a/user_registrationpassword.module
|+++ b/user_registrationpassword.module
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.
1 out of 1 hunk ignored

   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2024-09-03/user_registrationpassword-3467248-17.patch

> post-package-install: Drupal\Composer\Plugin\Scaffold\Plugin->postPackage

isalmanhaider’s picture

Issue summary: View changes

Just experienced on Drupal 11.2.2
with user_registrationpassword 2.0.2

While signing up a new user

mably’s picture

@isalmanhaider you replaced the issue summary with your comment.

isalmanhaider’s picture

@mably pardon for the inconvenience.

Just tried and patch #17 worked for me on Drupal 11.2.2 with PHP 8.3

lakhithad’s picture

Version 2.0.3 is released recently, but this bug seems to be still not fixed even in the recent version.

coretex’s picture

Is the phpunit test green or still failing? What are the last steps before merging?

intrafusion’s picture

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.