Call to a member function label() on null in Drupal\safedelete\AdminHelper::checkNodeReferencesMessage()

Created on 1 August 2023, over 1 year ago

Problem/Motivation

When using Safedelete on a site that also has Group module for content, deleting relations between a Node and a Group sometimes throws an uncaught exception WSOD error.

Error: Call to a member function label() on null in Drupal\safedelete\AdminHelper::checkNodeReferencesMessage() (line 420 of modules/contrib/safedelete/src/AdminHelper.php). 

The stack trace is below

safedelete_form_alter() (Line: 545)
Drupal\Core\Extension\ModuleHandler->alter() (Line: 840)
Drupal\Core\Form\FormBuilder->prepareForm() (Line: 284)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 270)
Drupal\shield\ShieldMiddleware->bypass() (Line: 137)
Drupal\shield\ShieldMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

On a site with Group and Safedelete.

  1. Visit a Group Nodes list - i.e., /group/6/nodes
  2. Use the "Delete relation" operation on a Node in the Group Nodes list

An uncaught exception is sometimes thrown. I'm not 100% sure how to reliably replicate the issue.

Proposed resolution

Ensure we do not try to call methods on an empty or null result. Add a try catch or defensive coding strategy that will output a useful error when this kind of problem occurs.

Remaining tasks

Write some tests.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇦🇺Australia chOP

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

Comments & Activities

Production build 0.71.5 2024