Problem/Motivation

I got this error when I tried to delete a node that had registrations on it:

The website encountered an unexpected error. Try again later.

Error: Call to a member function getSetting() on null in Drupal\registration_waitlist\EventSubscriber\RegistrationEventSubscriber->onDelete() (line 80 of modules/contrib/registration/modules/registration_waitlist/src/EventSubscriber/RegistrationEventSubscriber.php).
Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}(Object, 'registration.registration.delete', Object) (Line: 206)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners(Array, 'registration.registration.delete', Object) (Line: 56)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch(Object, 'registration.registration.delete') (Line: 57)
Drupal\registration\RegistrationStorage->invokeHook('delete', Object) (Line: 501)
Drupal\Core\Entity\EntityStorageBase->delete(Array) (Line: 753)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete(Array) (Line: 132)
Drupal\registration_purger\RegistrationPurger->purgeRegistrations(Object) (Line: 75)
Drupal\registration_purger\RegistrationPurger->onEntityDelete(Object) (Line: 14)
registration_purger_entity_delete(Object)
call_user_func_array('registration_purger_entity_delete', Array) (Line: 389)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}('registration_purger_entity_delete', 'registration_purger') (Line: 340)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_delete', Object) (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_delete', Array) (Line: 221)
Drupal\Core\Entity\EntityStorageBase->invokeHook('delete', Object) (Line: 1038)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('delete', Object) (Line: 501)
Drupal\Core\Entity\EntityStorageBase->delete(Array) (Line: 753)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete(Array) (Line: 378)
Drupal\Core\Entity\EntityBase->delete() (Line: 71)
Drupal\Core\Entity\ContentEntityDeleteForm->submitForm(Array, Object) (Line: 108)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 45)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 615)
Drupal\Core\Form\FormBuilder->processForm('node_event_delete_form', Array, Object) (Line: 347)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 634)
Drupal\Core\Render\Renderer::Drupal\Core\Render\{closure}()
Fiber->resume() (Line: 649)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 118)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 92)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 54)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 745)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Drupal 11.3.2

PHP 8.3

Install registration, registration_waitlist, and registration_purger

Might need to have some registrations on the node while trying to delete it; I don't think I got any error when I tried deleting an event node earlier that did not have any registrations on it.

Proposed resolution

I just encountered this a few minutes ago and haven't done deep tests, but my guess at this point is that what is happening is this order of operations:

1. Node gets deleted.
2. Registrations start being purged.
3. Once one registration is deleted, that means there's room to move another from the waitlist to complete and it tries to do so.
4. Except that the node it is trying to use that for, the $host_entity at the identified line 80, no longer exists.

If that's true, that solution might just be a type check to confirm that $host_entity is an instance of HostEntityInterface, not null, before proceeding to get its settings.

If I find some time, I'll come back and see what I can do for testing a solution, but in the meantime I'm happy for those more knowledgeable to run with it.

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

ryan-l-robinson created an issue. See original summary.

ryan-l-robinson’s picture

This is the same idea as #3569552 in terms of "what if the host entity doesn't exist anymore", but in a different place in the code, so I don't think that one will solve this one.

ryan-l-robinson’s picture

This line:

      $host_entity = $registration->getHostEntity();

Can return either HostEntityInterface or null. If it is null, it shouldn't try to getSetting on it. So I think the easiest way to achieve that is to add a null check on the if condition:

      $host_entity = $registration->getHostEntity();
      if ($host_entity?->getSetting('registration_waitlist_autofill')) {
        $this->waitListManager->autoFill($host_entity);
      }

There might be more complexity I'm missing here, but that seems to solve our problem.

john.oltman’s picture

That sounds right. I'll get fixes and tests committed to dev branch this weekend.

john.oltman’s picture

Title: Fatal Error Deleting Host Entity Node » Fatal error deleting host entity when purger and wait list enabled
Assigned: Unassigned » john.oltman

john.oltman’s picture

Title: Fatal error deleting host entity when purger and wait list enabled » Fatal error deleting host entity when wait list enabled

  • john.oltman committed 7085a101 on 3.4.x
    #3570197: Fatal error deleting host entity when wait list enabled
    
john.oltman’s picture

Version: 3.4.4 » 3.4.x-dev
Assigned: john.oltman » Unassigned
Status: Active » Fixed

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.