Error on first load of the configuration page. "AssertionError: Cannot load a NULL ID"

Created on 27 May 2020, about 4 years ago
Updated 13 February 2023, over 1 year ago

Problem/Motivation

After installation, visiting the configuration page returns the error:

AssertionError: Cannot load a NULL ID. in assert() (line 249 of /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php)
 #0 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(249): assert(false, 'Cannot load a N...')
 #1 /Users/****/Sites/****.****/releases/****.****/web/modules/contrib/backstop_generator/src/Form/BackstopConfigurationForm.php(85): Drupal\Core\Entity\EntityStorageBase->load(NULL)
 #2 [internal function]: Drupal\backstop_generator\Form\BackstopConfigurationForm->buildForm(Array, Object(Drupal\Core\Form\FormState))
 #3 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/Form/FormBuilder.php(519): call_user_func_array(Array, Array)
 #4 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/Form/FormBuilder.php(276): Drupal\Core\Form\FormBuilder->retrieveForm('backstop_config...', Object(Drupal\Core\Form\FormState))
 #5 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\backstop_generator\Form\BackstopConfigurationForm), Object(Drupal\Core\Form\FormState))
 #6 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
 #7 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
 #8 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
 #9 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
 #10 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
 #11 /Users/****/Sites/****.****/releases/****.****/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
 #12 /Users/****/Sites/****.****/releases/****.****/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
 #13 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #14 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #15 /Users/****/Sites/****.****/releases/****.****/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #16 /Users/****/Sites/****.****/releases/****.****/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #17 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #18 /Users/****/Sites/****.****/releases/****.****/web/modules/contrib/devel/webprofiler/src/StackMiddleware/WebprofilerMiddleware.php(38): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #19 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #20 /Users/****/Sites/****.****/releases/****.****/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #21 /Users/****/Sites/****.****/releases/****.****/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 #22 /Users/****/Sites/****.****/releases/****.****/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
 #23 {main}.

This error causesd a WSOD. Upon inspection, I found out that on the line #85 of src/Form/BackstopConfigurationForm.php \Drupal::entityTypeManager()->getStorage('node')->load($config->get($configString)) causes an error. The structure of that $config object is slightly different on our site. Probably due to the multiversion module that we're using or some other module, the pre_defined_pages_table.XXXXXXXXX.page key is not placed immediately in $config, but it's under overriddenData key. So DRUPAL throws an error immediately rather than returning null or FALSE.

Proposed resolution

Instead of only checking if \Drupal::entityTypeManager returns a value of null, the following check prevents the error:

if ($config->get($configString) && \Drupal::entityTypeManager()->getStorage('node')->load($config->get($configString)))

I've tested this check in our website with the multiversion module installed and a local Drupal site with no multiversion module. It loads the configuration module.

Remaining tasks

I am now writing a very simple patch so that you can test as well.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Add an extra check before loading nodes in the configuration

Original report by [username]

πŸ› Bug report
Status

Needs review

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom hocu London

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States wylbur Minneapolis, Minnesota, USA
Production build 0.69.0 2024