Group Content view errors - Call to a member function on null - after upgrade to 2.1.x

Created on 2 August 2023, almost 2 years ago

Problem/Motivation

After upgrade from Group v1.x to Group 2.1.x we are seeing some data errors where Group content have relations to missing entities. This results in WSOD uncaught exception errors like:

Error: Call to a member function label() on null in Drupal\group\Plugin\Group\RelationHandlerDefault\UiTextProvider->getRelationshipLabel() (line 35 of modules/contrib/group/src/Plugin/Group/RelationHandlerDefault/UiTextProvider.php). 

with call stack trace

Drupal\group\Plugin\Group\RelationHandler\EmptyUiTextProvider->getRelationshipLabel() (Line: 180)
Drupal\group\Entity\GroupRelationship->label() (Line: 242)
Drupal\Core\Entity\EntityBase->toLink() (Line: 114)
Drupal\group\Entity\Controller\GroupRelationshipListBuilder->buildRow() (Line: 242)
Drupal\Core\Entity\EntityListBuilder->render() (Line: 126)
Drupal\group\Entity\Controller\GroupRelationshipListBuilder->render() (Line: 23)
Drupal\Core\Entity\Controller\EntityListController->listing()
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

  1. Upgrade a site from Group v1.x to 2.1.x
  2. Visit the Groups list at /admin/group
  3. Choose an existing Group and list All entities - i.e., /admin/group/1/content

Proposed resolution

Use the null-safe operator for any call to access a method on an Entity relation to a Group. It seems that it is possible for a Group relation to reference a missing or empty entity. How that comes about might be a mystery, but it is definitely possible.

Once we fix the uncaught exceptions, any missing or empty Group relations can be safely deleted by a content editor with the right Group access permissions.

Remaining tasks

Add some tests.

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇦🇺Australia chOP

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

Comments & Activities

  • Issue created by @chOP
  • 🇦🇺Australia chOP

    Also seeing this uncaught exception error after fixing the first.

    Error: Call to a member function access() on null in Drupal\group\Entity\Controller\GroupRelationshipListBuilder->getDefaultOperations() (line 153 of modules/contrib/group/src/Entity/Controller/GroupRelationshipListBuilder.php). 
    

    with the call stack

    Drupal\Core\Entity\EntityListBuilder->getOperations() (Line: 212)
    Drupal\Core\Entity\EntityListBuilder->buildOperations() (Line: 194)
    Drupal\Core\Entity\EntityListBuilder->buildRow() (Line: 119)
    Drupal\group\Entity\Controller\GroupRelationshipListBuilder->buildRow() (Line: 242)
    Drupal\Core\Entity\EntityListBuilder->render() (Line: 126)
    Drupal\group\Entity\Controller\GroupRelationshipListBuilder->render() (Line: 23)
    Drupal\Core\Entity\Controller\EntityListController->listing()
    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)
    
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update almost 2 years ago
    9,627 pass
  • @chop opened merge request.
  • Status changed to Needs review almost 2 years ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    9,628 pass
  • 🇮🇳India shashank5563 New Delhi

    I have created a patch as well.

  • Status changed to RTBC 2 months ago
  • 🇺🇦Ukraine rollins

    I can confirm that provided patch resolved the bug

Production build 0.71.5 2024