I am using Drupal 10.1.2 version with PHP 8.1.24.

I have imported users and content from Drupal 7 to Drupal 10 by feeds. When working in Drupal 10 I have noticed that it is showing error when I am using views with user relationships. When opening admin/reports/dblog, the error is showing.

Error: Call to a member function getCacheMaxAge() on null in Drupal\views\Plugin\views\query\Sql->getCacheMaxAge() (line 1710 of /...../..../.../core/modules/views/src/Plugin/views/query/Sql.php).

Can anyone please let me know how to solve the issue?

Comments

Sandip Choudhury created an issue. See original summary.

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: -views, -Drupal 10, -relationship, -user +Needs steps to reproduce

Would you please obtain the stack trace and explain to us how to configure a view that shows this bug?

mjgruta’s picture

Hi @Sandip, we had similar issues but we upgraded from Drupal 8 to 10. in our case, the user id 0 was missing in the users table. I just created one and it seems to work fine now.

Version: 10.2.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

inversed’s picture

I'm also experiencing this on a new build and I'm wondering how this issue happened. This post's comment provides a patch but I'd like to understand the underlying cause.

https://www.drupal.org/forum/support/post-installation/2019-12-23/unexpe...

inversed’s picture

I found this which provides a possible explanation for how UID 0 is lost, what it does, and how to restore it:

https://www.drupal.org/docs/administering-a-drupal-site/troubleshooting-...

p.kasianov’s picture

Patch for d 10.3
I remove from index of results the record of missed entity and add log message with details.
It doesnt fix the reason of missed entity, but fix fatal + provide more details of it.

p.kasianov’s picture

StatusFileSize
new1021 bytes

Patch file

p.kasianov’s picture

StatusFileSize
new839 bytes

Updated log message

p.kasianov’s picture

Some update why this fatal error was happens.
Views gets result from database table, but when views trying to load entites in loadEntities (fucntion) it doesnt gets all entities. In my case the reason was in uncorectrly removed record of entity. Finnaly, it returned NULL, and get tryed to get maxCache from NULL.
If you will debug it, you see that in the assignEntitiesToResult function need to skip NULL and remove item from the result list.
The best solution as for me - it checks for empty on query level. But the perfomance will down.

p.kasianov’s picture

StatusFileSize
new838 bytes

Updated the name (Added issue number).

batkor’s picture

smustgrave’s picture

This was previously tagged for steps to reproduce, which appear to still be needed. If not provided this could be closed out.

batkor’s picture

My steps to reproduce.
I migrate users from Yii1.
After migrate in my drupal DB removed|lost anonymous user.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.