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
- Create a node that allows registrations, for example an Event node.
- Create one or more registrations associated with that node.
- Delete the host node without deleting its associated registrations.
- Navigate to
/admin/people/registrations. - 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3569552-cancel-by-access-null-host-entity.patch | 1.13 KB | isalmanhaider |
Issue fork registration-3569552
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
Comment #2
isalmanhaider commentedComment #3
isalmanhaider commentedComment #4
john.oltman commentedGood catch @isalmanhaider. I'll turn the patch into an MR and add a PHPUnit test for this condition within the next week.
Comment #7
john.oltman commentedFixed 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!