Hello,
Just after updating to Drupal 8.3.0 almost all my website frontend pages show this error:
The website encountered an unexpected error. Please try again later.
Error: Call to a member function getTotalCount() on boolean in statistics_get() (line 129 of core/modules/statistics/statistics.module).
statistics_get('94') (Line: 142)
darna_preprocess_node(Array, 'node', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 435)
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: 574)
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) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Do you have any idea on how to solve it?
Regards
Comment | File | Size | Author |
---|---|---|---|
#27 | 2867493-27.patch | 3.29 KB | alexpott |
#27 | 24-27-interdiff.txt | 761 bytes | alexpott |
#24 | 2867493-24.patch | 3.29 KB | alexpott |
#24 | 19-24-interdiff.txt | 1.22 KB | alexpott |
#19 | statistics-2867493-14.patch | 2.08 KB | xjm |
Comments
Comment #2
webchickReviewing the list of commits to statistics module since August 1, seems like the most likely culprit is probably #1446932: Improve statistics performance by adding a swappable backend, as it touched the statistics_get() function.
That reset() call will return FALSE if $views is an empty array, which it would be if it were checking against a node ID that no longer existed, for example.
I see this call to statistics_get() is coming from your theme; is it possible it's checking against an expired node ID? Or is this happening on every page?
Comment #3
connectedrobots CreditAttribution: connectedrobots commentedHello and thank you for yout reply,
What do you mean by expired node ID? A node ID which no longer exists?
The problem appears on several pages but not on all: frontpages and blog pages seem not to affected.
Do you need more information?
I am really worried about this problem.
Regards
Comment #4
timmillwoodThanks for reporting this.
I'll try to get a fix tomorrow if no one else has by then. I think we just need to put a few checks in place.
Comment #5
cilefen CreditAttribution: cilefen commentedWe need some test coverage.
Comment #6
xjmI have a test; will post shortly.
Comment #7
catchJust a note I thought we'd seen something like this before, but it wasn't, it was #2616330: statistics.php can exit early and prevent output errors which won't help here - in case anyone has the same thought.
Comment #8
xjmSo yeah, this is a small BC break for
statistics_get()
. In 8.2.x it would have returned FALSE for an invalid node ID; in 8.3.x/8.4.x it fatals. Attached demonstrates the fatal. I also manually removed a couple lines of context to prove it works on 8.2.x.Comment #9
xjmAnd with the fix. This is why we want deprecated test coverage (both dedicated tests for deprecated code and tests to check for deprecated code).
Comment #10
xjmAdding a more explicit comment in the test. This probably still won't stop someone from converting it indiscriminately, but it at least should stop us from committing their indiscriminate conversion.
Comment #11
timmillwoodInstead of checking its empty should be instead check it's a StatisticsViewsResult object.
Comment #12
xjmSure, that makes sense. More robust that way BC-wise.
Comment #13
catchShould be FALSE rather than empty array no?
Otherwise looks good.
Comment #14
xjmRight.
Comment #15
timmillwoodAwesome turnaround
Comment #16
xjmThis will get NW in a bit once that interdiff gets tested. ;)
Probably should wait for CI in any case.
Comment #19
xjmAs above.
Comment #20
cilefen CreditAttribution: cilefen commentedComment #21
cilefen CreditAttribution: cilefen commented@connectedrobots Are you able to manually test the patch in comment #19?
Comment #22
xjmThe test-only patch in #8 also shows the exact fatal BTW (in the console output):
Comment #23
xjmDidn't mean to leave this assigned to myself.
Comment #24
alexpottVery minor docs improvements so other consumers of the new API might expect it to work this way. Fortunately, statistics_node_links_alter() does it right.
Comment #25
xjmThe words and the datatype here do not agree -- datatype says it's a nested array.
Edit: Or I guess the datatype is not valid phpdoc? So probably a typo in fixing the typo.
Comment #26
xjmBTW not entirely sure the bad docs are in scope to begin with; while they could cause this bug in other code, they probably didn't in
statistics_get()
since that was in the same patch where they were added.(And also
statistics_get()
not retaining BC is its own bug regardless of what API replaces it.)Comment #27
alexpottI dunno it was not being aware of this whilst converting statistics_get() to use the new API that caused the bug. If we'd had the correct docs you can programmatically work out where code doesn't code for all possibilities. PHPStorm for example can be set up to do this.
Comment #28
xjmOkay.
I guess I can RTBC this since the docs changes correlate to what I saw in the patch @timmillwood previously RTBCed and it's a docs addition/fix. Someone other than me or @alexpott should commit the patch though.
Comment #31
cilefen CreditAttribution: cilefen commentedThank you everyone!
Committed c2f6edd and pushed to 8.4.x. Cherry-picked as 3689c11 and pushed to 8.3.x.
Comment #32
connectedrobots CreditAttribution: connectedrobots commentedHello all of you and thank you for your replies,
As I am not very familiar with the Drupal issues discussions I do not really understand where do we stand now. Should I apply patch in comment # 19, 24 or 27?
Regards
Comment #33
webchickGenerally-speaking, always go for the latest patch, which in this case is #27.
However! In this case, this change was already made to the code base, so you should be able to upgrade to the 8.3.x-dev release and see/test the fix.
Comment #34
connectedrobots CreditAttribution: connectedrobots commentedHello and thank you for your reply,
I uploaded the patch to the www/core/modules/statistics folder and when I try to apply it I get this notice:
can't find file to patch at input line 32
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/core/modules/statistics/src/Tests/StatisticsLoggingTest.php b/core/modules/statistics/src/Tests/StatisticsLoggingTest.php
|index 152c95a..6f2f667 100644
|--- a/core/modules/statistics/src/Tests/StatisticsLoggingTest.php
|+++ b/core/modules/statistics/src/Tests/StatisticsLoggingTest.php
Do you know what is the problem?
webchick you said
but I can not find this release.I only see the 8.4.x-dev one.
Regards
I did not checked my website then. The problem seems to be fixed.
Comment #35
catchThe patch is against the root of the Drupal core directory rather than the statistics module, try applying from there.
8.3.x dev release is here:
https://www.drupal.org/project/drupal/releases/8.3.x-dev
Comment #36
connectedrobots CreditAttribution: connectedrobots commentedHello and thank you for your reply,
catch I do not know what should I do now. As I told you the problem seems to be fixed but apparently I applied the patch at the wrong place (www/core/modules/statistics). What should I do according to you? Reinstall Druapl 8.3.0 core statistics module and apply patch here: www/core? Upgrade the whole website to Drupal 8.3.0-dev? Do nothing?
Regards
Comment #37
cilefen CreditAttribution: cilefen commentedAll core patches are created with respect to the base of the Drupal installation, not /core. So, I think, in this case you should be in directory "www", not "www/core" when you apply the patch.
Comment #38
connectedrobots CreditAttribution: connectedrobots commentedHello and thank you for your reply,
cilefen are you sure ? Anyway thank you for the precision but that does not tell me what to do.
Regards
Comment #39
xjmHi @connectedrobots,
In the short term, updating to the current 8.3.x-dev release as @catch above linked it would probably be a good way to ensure that the bug does not resurface, especially if you are unsure whether or not the patch was applied or about maintaining a site with a patch running. If you do use the development release, just be sure to update it again to the latest dev code whenever there are announcements of new releases, especially security releases.
The next scheduled bugfix release for Drupal core is May 3. There could be other releases between now and then that might not include this fix, but the May 3 release almost certainly will. So after May 3 you should be able to update Drupal to a stable release and count on Drupal updates to work normally again after that. Just keep an eye on the release notes for any release between now and then. The first release that includes this fix will mention it prominently in the release notes.
I hope this helps! Thanks again for reporting this issue right away.