## UPDATE

This issue appears to be already fixed in the 3.0.x-dev branch (commit 71161f2).

The fix uses `getEntityId()` and `getGroupId()` instead of `getEntity()->id()` and `getGroup()->id()`, which prevents the null pointer error when users are deleted.

**Affected version:** 3.0.0-rc2
**Fixed in:** 3.0.x-dev

The issue still exists in the RC2 release, so a new stable release (3.0.1 or 3.0.0 final) would be beneficial to get this fix into production sites.

**Workaround:** Use `drupal/ginvite: "3.0.x-dev"` in composer.json until a stable release is available.

Problem/Motivation

When attempting to delete users using the purge_users module (or any method that deletes users who are group members), a fatal PHP error occurs:

Error: Call to a member function id() on null in ginvite_group_content_delete() (line 209 of modules/contrib/ginvite/ginvite.module)

This happens because when a user is being deleted, their group membership relationships are also deleted as part of the cascade. However, by the time the ginvite_group_content_delete() hook is invoked, the user entity referenced by $group_relationship->getEntity() may already be null, causing the fatal error when trying to call ->id() on it.

The problematic code is in ginvite.module lines 207-218:

// Remove invitation when member is removed.
if ($plugin_id == 'group_membership') {
  $properties = [
    'entity_id' => $group_relationship->getEntity()->id(),  // ← Can be null
    'gid' => $group_relationship->getGroup()->id(),         // ← Can be null
  ];

  // Remove invitations, when we remove the user.
  $invitations = \Drupal::service('ginvite.invitation_loader')->loadByProperties($properties);
  foreach ($invitations as $invitation) {
    $invitation->getGroupRelationship()->delete();
  }
}

Steps to reproduce

1. Install and enable the ginvite module (version 3.0.0-rc2)
2. Install and enable the purge_users module
3. Create a group and add user members to it
4. Attempt to delete one of the member users via the purge_users interface (/admin/people/purge-users)
5. Observe fatal PHP error

Full stack trace:

ResponseText: The website encountered an unexpected error. Try again later.
Error: Call to a member function id() on null in ginvite_group_content_delete() (line 209 of modules/contrib/ginvite/ginvite.module). 
call_user_func_array(Object, Array) (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'ginvite') (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('group_content_delete', Object) (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll('group_content_delete', Array) (Line: 215)
Drupal\Core\Entity\EntityStorageBase->invokeHook('delete', Object) (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('delete', Object) (Line: 462)
Drupal\Core\Entity\EntityStorageBase->delete(Array) (Line: 753)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete(Array) (Line: 457)
group_entity_delete(Object)

Proposed resolution

Add null checks for both getEntity() and getGroup() before attempting to call ->id() on them. This prevents the fatal error when the entity is already being deleted and is no longer available.

The fix should:

  • Store the results of getEntity() and getGroup() in variables
  • Check if both are non-null before proceeding
  • Only attempt to clean up invitations if the entity and group still exist

A patch will be attached that implements this fix.

Remaining tasks

  • Review and test the attached patch
  • Confirm it resolves the issue without introducing side effects
  • Commit the fix
  • Backport to other supported branches if applicable

User interface changes

None

API changes

None

Data model changes

None

Issue fork ginvite-3555553

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

brooke_heaton created an issue. See original summary.

brooke_heaton’s picture

Issue summary: View changes
Status: Active » Needs review

This issue appears to be already fixed in the 3.0.x-dev branch (commit 71161f2).

The fix uses `getEntityId()` and `getGroupId()` instead of `getEntity()->id()` and `getGroup()->id()`, which prevents the null pointer error when users are deleted.

**Affected version:** 3.0.0-rc2
**Fixed in:** 3.0.x-dev

The issue still exists in the RC2 release, so a new stable release (3.0.1 or 3.0.0 final) would be beneficial to get this fix into production sites.

**Workaround:** Use `drupal/ginvite: "3.0.x-dev"` in composer.json until a stable release is available.

lobsterr’s picture

Status: Needs review » Fixed

A new release was tagged. Please check it

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.