Fatal error on admin/content

Created on 22 August 2017, about 7 years ago
Updated 16 May 2024, 6 months ago

Issue

When using Workspace, the admin/content page stops working.

How to replicate

  • Install lightning profile 8.x-2.17
  • Install Deploy
  • Create some new content
  • Switch workspace

Error Trace

[22-Aug-2017 17:39:37 UTC] Error: Call to a member function getCacheTags() on null in docroot/core/modules/views/src/Plugin/views/query/Sql.php on line 1622 #0 docroot/core/modules/views/src/Plugin/views/cache/CachePluginBase.php(236): Drupal\views\Plugin\views\query\Sql->getCacheTags()
#1 docroot/core/modules/views/src/Plugin/views/cache/CachePluginBase.php(113): Drupal\views\Plugin\views\cache\CachePluginBase->getCacheTags()
#2 docroot/core/modules/views/src/ViewExecutable.php(1417): Drupal\views\Plugin\views\cache\CachePluginBase->cacheSet('results')
#3 docroot/core/modules/views/src/ViewExecutable.php(1440): Drupal\views\ViewExecutable->execute(NULL)
#4 docroot/core/modules/views/src/Plugin/views/display/Page.php(171): Drupal\views\ViewExecutable->render()
#5 docroot/core/modules/views/src/ViewExecutable.php(1616): Drupal\views\Plugin\views\display\Page->execute()
#6 docroot/core/modules/views/src/Element/View.php(78): Drupal\views\ViewExecutable->executeDisplay('page_1', Array)
#7 [internal function]: Drupal\views\Element\View::preRenderViewElement(Array)
#8 docroot/core/lib/Drupal/Core/Render/Renderer.php(376): call_user_func(Array, Array)
#9 docroot/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)
#10 docroot/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(226): Drupal\Core\Render\Renderer->render(Array, false)
#11 docroot/core/lib/Drupal/Core/Render/Renderer.php(574): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#12 docroot/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(227): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#13 docroot/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#14 docroot/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#15 docroot/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#16 docroot/vendor/symfony/http-kernel/HttpKernel.php(149): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent))
#17 docroot/vendor/symfony/http-kernel/HttpKernel.php(64): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#18 docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 docroot/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 docroot/core/lib/Drupal/Core/DrupalKernel.php(656): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#27 {main}

Temporary Fix

I did this temporary fix in my code to be able to get it to work:

File:

  /**
   * Gets all the involved entities of the view.
   *
   * @return \Drupal\Core\Entity\EntityInterface[]
   */
  protected function getAllEntities() {
    $entities = [];
    foreach ($this->view->result as $row) {
      if ($row->_entity) {
        $entities[] = $row->_entity;
      }
      foreach ($row->_relationship_entities as $entity) {
        if ($entity) {
          $entities[] = $entity;
        }
      }
    }

    return $entities;
  }

       }
       foreach ($row->_relationship_entities as $entity) {
-        $entities[] = $entity;
+        if ($entity) {
+          $entities[] = $entity;
+        }
       }
     }
πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡¨πŸ‡·Costa Rica pviquez@pabloviquez.com

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    @ pviquez@pabloviquez.com, Thank you for reporting this problem. We rely on issue reports like this one to resolve bugs and improve Drupal core.

    Is this issue still a problem?

    There has been no activity here for 5 years (not counting the reroll) when a maintainer asked for steps to reproduce. See #20.

    If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete

    Since we need more information to move forward with this issue, I am setting the status at Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

  • πŸ‡©πŸ‡ͺGermany keinstein

    I just came across this issue with 9.5.x. so it is still active.

    @Lendude The root cause for this bug is that the object is left in an invalid internal state. Everything else depends on this bug. Either the triggering code is not fixed because the error is accepted by assignEntitiesToResult or several functions in core/modules/views/src/Plugin/views/query/Sql.php are broken and shoudl be fixed that the invalid state is correct.

    A short scan over my Drupal installations reveals that it's nearly impossible to decide what is intended.
    Here are the results:

    $ grep -e '_relationship_entities' -r .|grep -v test
    ./core/modules/views/src/ResultRow.php:  public $_relationship_entities = [];
    ./core/modules/views/src/ResultRow.php:   * Resets the _entity and _relationship_entities properties.
    ./core/modules/views/src/ResultRow.php:    $this->_relationship_entities = [];
    ./core/modules/views/src/Plugin/views/cache/CachePluginBase.php:    if (!empty($row->_relationship_entities)) {
    ./core/modules/views/src/Plugin/views/cache/CachePluginBase.php:	    foreach ($row->_relationship_entities as $key => $entity) {
    ./core/modules/views/src/Plugin/views/cache/CachePluginBase.php:    $row_data = array_diff_key((array) $row, array_flip(['index', '_entity', '_relationship_entities'])) + $this->getRowCacheTags($row);
    ./core/modules/views/src/Plugin/views/field/FieldPluginBase.php:    elseif (isset($values->_relationship_entities[$relationship_id])) {
    ./core/modules/views/src/Plugin/views/field/FieldPluginBase.php:      return $values->_relationship_entities[$relationship_id];
    ./core/modules/views/src/Plugin/views/query/QueryPluginBase.php:   * $result->_relationship_entities[$relationship_id];
    ./core/modules/views/src/Plugin/views/query/Sql.php:   * $result->_relationship_entities[$relationship_id];
    ./core/modules/views/src/Plugin/views/query/Sql.php:          $results[$index]->_relationship_entities[$relationship_id] = $entity;
    ./core/modules/views/src/Plugin/views/query/Sql.php:      foreach ($row->_relationship_entities as $entity) {
    

    As you can see _relationship_entities is a public member. So CachePluginBase Sql.php cannot rely on non-null entries in _relationship_entities. So my suggestion is:

    • In the next major release: Throw an exception if an entity is not valid in assignEntitiesToResult
    • In all other releases issue a warning instead and silently accept the invalid state without crashing in getAllEntities

    Currently code must always check that a certain key contains no null value. With the fix in place people must check that the key exists. What you prefer is a question of coding style and which one is faster depends on the actual application.

  • πŸ‡¦πŸ‡ΊAustralia gordon Melbourne

    This problem seems to be related to #2738051 πŸ› \Drupal\views\Plugin\views\query\Sql::getCacheTags and getCacheMaxAge don't take into account that some entities can be NULL Needs work , but in my case the other didn't fix my issue but caused another issue, and this one fixed it. They both seem to be a very similar issue and solved in slightly different methods.

Production build 0.71.5 2024