For some reason this error sometimes appears.
Any solutions ? Drupal 8.7.8
The website encountered an unexpected error. Please try again later.
Error: Call to a member function getCacheMaxAge() on null in Drupal\views\Plugin\views\query\Sql->getCacheMaxAge() (line 1690 of core/modules/views/src/Plugin/views/query/Sql.php).
Drupal\views\Plugin\views\query\Sql->getCacheMaxAge() (Line: 260)
Drupal\views\Plugin\views\cache\CachePluginBase->getCacheMaxAge() (Line: 677)
Drupal\views\Plugin\views\style\StylePluginBase->renderFields(Array) (Line: 576)
Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping(Array, Array, 1) (Line: 468)
Drupal\views\Plugin\views\style\StylePluginBase->render(Array) (Line: 2111)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 1533)
Drupal\views\ViewExecutable->render() (Line: 183)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay('page_ei', Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func(Array, Array) (Line: 378)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comments
Make the code more robust
When line 1690:
it is part of a foreach assuming it finds entities. Suggest to assign the found entities to a variable and make the foreach conditional to being an array:
Note that doesn't calculate the max_age correctly. No idea why, you may want to trigger an exception or log that it can't find the entities.
Thank you for your help.
Thank you for your help.
I tried your suggestion, but no success.
The website encountered an unexpected error. Please try again later.ParseError: syntax error, unexpected 'foreach' (T_FOREACH) in Composer\Autoload\includeFile() (line 1691 of core/modules/views/src/Plugin/views/query/Sql.php).
I am not familiar with drupal code and log doesn't shaw which entities not found.
Sorry, typo in code
Missing closing bracket on if.
should be:
Yeah bracket was missing, I
Yeah bracket was missing, I added and now comes out
The website encountered an unexpected error. Please try again later.ParseError: syntax error, unexpected 'protected' (T_PROTECTED) in Composer\Autoload\includeFile() (line 1703 of core/modules/views/src/Plugin/views/query/Sql.php).
Sounds like you forgot the closing }
That causes the function not to end, not understanding that protected is defining a new function.
You are right. Thank you very
You are right. Thank you very much
The website encountered an
The website encountered an unexpected error. Please try again later.Error: Call to a member function getCacheMaxAge() on null in Drupal\views\Plugin\views\query\Sql->getCacheMaxAge() (line 1692 of core/modules/views/src/Plugin/views/query/Sql.php).
I was thinking its resolved, but happening again. And this time it happen at logout.
Sounds like data corruption in views
There are multiple ways to resolve this, purely based on the code I would go for:
Added two !empty() function calls to avoid adding those entries.
You could instead make
conditional to !empty($entity
Would probably prefer this because it is not depending on other function to produce the expect result for your function.
As mentioned there probably is some data corruption in your views. Suggest inspecting and correcting them.
Both ways return same error
Both ways return same error
The website encountered an unexpected error. Please try again later.Error: Call to a member function getCacheTags() on null in Drupal\views\Plugin\views\cache\CachePluginBase->getRowCacheTags()
(line 318 of core/modules/views/src/Plugin/views/cache/CachePluginBase.php).
By second way, I cleared all
By second way, I cleared all caches, seems works so far
Again, sometimes the same
Again, sometimes the same error comes out
Error: Call to a member function getCacheTags() on null in Drupal\views\Plugin\views\cache\CachePluginBase->getRowCacheTags() (line 318 of core/modules/views/src/Plugin/views/cache/CachePluginBase.php).after clear all caches works fine
Indeed the same issue exists for tags
But it is not the same as for maxAge. The solution is the same though. Put a test around it.
I did the same solution for
I did the same solution for
$tags = Cache::mergeTags($tags, $entity->getCacheTags());works so far, let's see what will happen. Thank you so much
Making these changes by using !is_null works fine for me
File : core/modules/views/src/Plugin/views/cache/CachePluginBase.php
line: 320
if(!is_null($entity)){
$tags = Cache::mergeTags($tags, $entity->getCacheTags());
}
File: /core/modules/views/src/Plugin/views/query/Sql.php
Line: 1695
if(!is_null($entity)){
$max_age = Cache::mergeMaxAges($max_age, $entity->getCacheMaxAge());
}
Sql.php file
Line: 1682
if(!is_null($entity)){
$tags = Cache::mergeTags($entity->getCacheTags(), $tags);
}
I have try this patch and it is working fine for me
diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/modules/views/src/Plugin/views/query/Sql.php
index 47f229f9..1e8e4da6 100644
--- a/core/modules/views/src/Plugin/views/query/Sql.php
+++ b/core/modules/views/src/Plugin/views/query/Sql.php
@@ -1707,7 +1707,9 @@ class Sql extends QueryPluginBase {
public function getCacheMaxAge() {
$max_age = parent::getCacheMaxAge();
foreach ($this->getAllEntities() as $entity) {
- $max_age = Cache::mergeMaxAges($max_age, $entity->getCacheMaxAge());
+ if(!is_null($entity)){
+ $max_age = Cache::mergeMaxAges($max_age, $entity->getCacheMaxAge());
+ }
}
return $max_age;
Patch works but question why the code isn't more robust?
Thank you @ajaysinh from a year and a half ago. Running a D10.3 site and came across this issue recently. I ended up having to patch in 3 places.
I question why core would have a naked call like this. It should be more robust and only throw a warning/error message not a WSOD. Is there a place to report / query on this issue? Thanks.
Linking to issue queue
In case anyone lands on this post, as I did, from a search engine link; there is an open issue at the time of posting in the Drupal core issue queue https://www.drupal.org/project/drupal/issues/3169694.