Fatal error "getCacheTags() on null" on admin/content Views page

Created on 8 September 2020, over 4 years ago
Updated 6 June 2023, over 1 year ago

Problem/Motivation

/admin/content view is not working - fatal error.

Dblog reports 3 different errors:
Error: Call to a member function getCacheTags() on null in Drupal\views\Plugin\views\query\Sql->getCacheTags() (Line 1677 in /app/web/core/modules/views/src/Plugin/views/query/Sql.php)

Error: Call to a member function getCacheMaxAge() on null in Drupal\views\Plugin\views\query\Sql->getCacheMaxAge() (Line 1694 in /app/web/core/modules/views/src/Plugin/views/query/Sql.php)

Error: Call to a member function getCacheTags() on null in Drupal\views\Plugin\views\cache\CachePluginBase->getRowCacheTags() (Zeile 320 in /app/web/core/modules/views/src/Plugin/views/cache/CachePluginBase.php)

The issue lies in web/core/modules/views/src/Plugin/views/query/Sql.php in getAllEntities(line 1707) method, where $row->_relationship_entities can be NULL but are not checked if emtyp (as $row->_entity is).

Steps to reproduce

It is related to our content so I'm not sure how exactly to reproduce. On some of our migrated nodes an entity reference field is missing.

Proposed resolution

I would actually put a check into the 3 methods that are throwing php errors to check if the entity is not empty and then perform caching operations (merging tags or getRowCacheTags).

🐛 Bug report
Status

Closed: works as designed

Version

9.2

Component
Views 

Last updated 2 days ago

Created by

🇸🇮Slovenia useernamee Ljubljana

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.

  • 🇲🇼Malawi chancenyasulu

    Can we change this parts

    if (empty($entity)) {
    + continue;
    + }

    by using !is_null and instead of continue; replace it with these lines

    first part: $tags = Cache::mergeTags($tags, $entity->getCacheTags());
    second part: $tags = Cache::mergeTags($entity->getCacheTags(), $tags);
    third part: $max_age = Cache::mergeMaxAges($max_age, $entity->getCacheMaxAge());

    if (empty($entity)) {
    $tags = Cache::mergeTags($tags, $entity->getCacheTags());
    }

  • 🇺🇸United States pramodganore

    Any idea, when will this be merged into Drupal 10 ?

  • 🇺🇸United States TimeFor

    I encountered an error which was due to a corrupted entry in the 'users' table of the database. The issue arose when I transferred data between environments: MySQL failed to create the anonymous user with UID=0, instead assigning the next available UID. This newly assigned UID had no corresponding entry in the 'users_data' table, causing disruptions in views loading content associated with the anonymous user.

    Though the above patch helped identify the root cause, it wasn't a permanent fix. To resolve the problem, I manually set the UID for the anonymous user to 0 in the database, eliminating the need for the patch.

    I used Navicat MySQL for data transfer, but I'm uncertain if that's where the UID discrepancy began, or if it might be related to some default setting within the SQL database that prevents assignment of a UID of 0.

  • 🇬🇧United Kingdom robcarr Perthshire, Scotland

    @TimeFor - thanks for solution. I'd seen the error and it was exactly that issue where I'd transferred databases between environments. Worth noting as a potential Drupal general problem.

    It was a case of looking in users_field_data table and comparing UIDs to the users table and seeing where there was a mismatch. In my case it was the highest UID in the users table that was erroneous - just edited the users table in PMA and altered the relevant UID value to 0

  • 🇬🇧United Kingdom sadikyalcin

    @TimeFor what a life saver. That was exactly the issue for me. I moved to a new db and watchdog kept breaking with cache errors.

    Error: Call to a member function getCacheTags()
    Error: Call to a member function getCacheMaxAge()

Production build 0.71.5 2024