getOwner(): Return value must be of type Drupal\user\UserInterface, null returned

Created on 14 July 2025, 22 days ago

Problem/Motivation

TypeError: Drupal\sitewide_alert\Entity\SitewideAlert::getOwner(): Return value must be of type Drupal\user\UserInterface, null returned in Drupal\sitewide_alert\Entity\SitewideAlert->getOwner() (line 174 of /var/www/html/docroot/modules/contrib/sitewide_alert/src/Entity/SitewideAlert.php)

Steps to reproduce

Create a sitewide alert
and edit the created one
eg- /admin/content/sitewide_alert/6

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia suryabhi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @suryabhi
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia suryabhi
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia suryabhi
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia suryabhi
  • Pipeline finished with Success
    22 days ago
    Total: 321s
    #546750
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia suryabhi
  • I have tested this issue as per the provided steps:

    Created a Sitewide Alert.

    Edited the alert via /admin/content/sitewide_alert/{id}.

    Also tried deleting the user who created the alert (with โ€œDelete the account and make its content belong to the Anonymous userโ€ option).

    However, I was not able to reproduce the TypeError mentioned in the issue summary. The alert edit page loads without any errors, and I do not see any related entries in the Watchdog logs (/admin/reports/dblog).

    To ensure I'm not missing something, could you please elaborate on the exact conditions required to trigger the error (e.g., should the owner field be manually unset or reference a missing UID)?

    It would also be helpful if you could re-test this on your end and confirm whether it is still reproducible with the current codebase.

    Thanks!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia suryabhi

    1. Create a different role
    2. Create a user with that role
    3. Give add and edit sitewide alert permission to the user
    4. then try access to /admin/content/sitewide_alert/6

    Hope you will able to reproduce the error. I am not reproduce the error with user 1 and the have followed the above step

  • @suryabhi
    i have also follow these new steps but still i am uable to reproduce this issue , i have created new role and a new user of that role. Then with that new user I tried to edit the content created by the admin and also tried to edit the sitewide created by that new user with the admin's role. In both the cases I did't get ay error, pls tell me if I am missing somethig here.

    Thanks,

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom malcomio

    One factor that may be relevant is that @suryabhi and I work on a project which previously used the 2.x branch of the module and has been updated to use the 3.x branch.

    I've been able to reproduce this issue when trying to edit an old alert, but it doesn't seem to happen for newly created alerts.

    The merge request does not address the problem, as the return value can still be null.

  • Pipeline finished with Success
    12 days ago
    Total: 146s
    #555862
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom malcomio

    I've pushed a change in the branch that handles this scenario, but I think that the real problem is that the module does not implement hook_user_cancel - see ๐Ÿ“Œ Implement hook_user_cancel Active

Production build 0.71.5 2024