Problem/Motivation

When a registration's host entity (e.g., a node) is deleted but the registration record remains in the database, accessing the registrations listing page at /admin/people/registrations results in a fatal error:

"Call to a member function getSettings() on null in Drupal\registration_cancel_by\Access\CancelByAccessCheck->access() (line 67)"

This occurs because the CancelByAccessCheck::access() method does not check if the host entity exists before calling getSettings() on it.

Steps to reproduce

  1. Create a node that allows registrations, for example an Event node.
  2. Create one or more registrations associated with that node.
  3. Delete the host node without deleting its associated registrations.
  4. Navigate to /admin/people/registrations.
  5. The page throws a fatal error when rendering the operations links for orphaned registrations because the referenced host node no longer exists.

Proposed resolution

Add a null check for the host entity before attempting to call getSettings(). If the host entity no longer exists, return a forbidden access result with an appropriate message and cache dependency on the registration entity.

This makes the code defensive and prevents fatal errors when registrations exist without valid host entities, which can happen in several scenarios:

  • Host entity is manually deleted from the database.
  • Host entity deletion fails to clean up associated registrations.
  • Database inconsistency from migration or import processes.
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

isalmanhaider created an issue. See original summary.

isalmanhaider’s picture

isalmanhaider’s picture

Status: Active » Needs review
john.oltman’s picture

Good catch @isalmanhaider. I'll turn the patch into an MR and add a PHPUnit test for this condition within the next week.

  • john.oltman committed 7f69f7b6 on 3.4.x
    #3569552: CancelByAccessCheck throws fatal error when host entity is...
john.oltman’s picture

Component: Registration Core » Registration Cancel By
Assigned: isalmanhaider » Unassigned
Status: Needs review » Fixed

Fixed and committed to dev branch, will be in the next release. I did not use the patch directly, as returning Forbidden cannot be overridden by custom modules, so I avoided that. But it follows a similar concept. Thank you!

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.