Problem/Motivation
With a views pager set to 'Allow user to display all items' in the 'Exposed Options' section, along with setting the exposed items per page options set, when viewing the page if the user selects '- All -' from the Items per page select list, this causes a white screen unexpected error to appear when the filter is applied. The error message is below:
This only happens with PHP 8. I can reproduce this behaviour on multiple sites. Tried to test it with simplytest.me, but looks like that is still running only PHP 7.3 so does not error.
TypeError: Unsupported operand types: int * string in Drupal\views\Plugin\views\pager\SqlBase->query() (line 279 of /var/www/html/core/modules/views/src/Plugin/views/pager/SqlBase.php)
#0 /var/www/html/core/modules/views/src/Plugin/views/pager/Mini.php(48): Drupal\views\Plugin\views\pager\SqlBase->query()
#1 /var/www/html/core/modules/views/src/Plugin/views/query/Sql.php(1457): Drupal\views\Plugin\views\pager\Mini->query()
#2 /var/www/html/core/modules/views/src/ViewExecutable.php(1321): Drupal\views\Plugin\views\query\Sql->build(Object(Drupal\views\ViewExecutable))
#3 /var/www/html/core/modules/views/src/Plugin/views/display/PathPluginBase.php(395): Drupal\views\ViewExecutable->build()
#4 /var/www/html/core/modules/views/src/Plugin/views/display/Page.php(196): Drupal\views\Plugin\views\display\PathPluginBase->execute()
#5 /var/www/html/core/modules/views/src/ViewExecutable.php(1630): Drupal\views\Plugin\views\display\Page->execute()
#6 /var/www/html/core/modules/views/src/Element/View.php(81): Drupal\views\ViewExecutable->executeDisplay('page_1', Array)
#7 [internal function]: Drupal\views\Element\View::preRenderViewElement(Array)
#8 /var/www/html/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array(Array, Array)
#9 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(772): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
#10 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(363): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array)
#11 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#12 /var/www/html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(241): Drupal\Core\Render\Renderer->render(Array, false)
#13 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#14 /var/www/html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(242): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#15 /var/www/html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(132): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#16 /var/www/html/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))
#17 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#18 /var/www/html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(163): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#20 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#21 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#30 {main}
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
cilefen commentedIt is reproducible and as it's an exception you can cause in the UI, it's major priority. I updated the IS with a stack trace.
Comment #3
cilefen commentedIt is of course caused by loose typing. But the problem goes deep. If you do some typecasting in SqlBase::query, you then have to backtrack through the calling code because of the same problem.
Comment #4
cilefen commentedThere is actually a lot to be done. This fixes it for the mini-pager (I think). It's just a first pass.
Comment #5
cilefen commented#4 definitely doesn't work. There is no exception, but you only get one item for selecting '--All--'.
Comment #6
longwaveI don't want to have to add this tag as I know how difficult Views tests can be, but this is a case where we really need some more.
Comment #7
cilefen commentedComment #8
carsteng commentedPath in #4 is not good.....
The root problem here is that with Line 263 in SqlBase.php with php8.0 returns true.
Comment #9
carsteng commentedAnd here is the patch:
Comment #10
carsteng commentedComment #11
david.qdoscc commented@carstenG thank you for the fantastically simple fix! Patch #9 does the job :)
Comment #12
cilefen commentedAlright let's add the test coverage.
Comment #14
fkildoo commentedPatch #9 fixed the issue on my end.
Comment #15
freddy rodriguezThere is a kind of strange glitch: With the patch #9 applied, the error appears only right after saving the display. If the user re-enters the view and saves, everything seems to work normally.
The patch#9 was tested in D9.4.3 - PHP 8.0.21
Comment #16
jshimota01 commentedtested #9 successfully - php 8.1.6, d9.4.5 - had to clear Views Cache
Comment #17
brewerkr commentedwhen I try #9, I just get a blank page. Drupal 9.4.5 PHP 8.0.20. I was getting the same when I was at D9.4.3 (thus the upgrade to 9.4.5 with fingers crossed). Also tried using PHP 8.1 with same result (but got deprecation errors for another module so went back to PHP 8.0)
Comment #18
davidhk commentedI applied the patch, cleared all caches, and now the 'All' value of items-per-page works again. I'm using Drupal 9.4.5 with PHP 8.0.23.
Comment #19
nlisgo commentedI'm going to attempt to add a test for this.
Comment #20
nlisgo commentedComment #22
nlisgo commentedI've created a merge request initially adding a test that will expose the error described in this issue to CI. Once this fails I will add a commit which applies the patch in #9 and CI should then pass.
Comment #24
nlisgo commentedAfter chatting with @xjm I have decided it is best to have 2 merge requests. One which has the test and patch and the other which is test only.
- test and fix
- test only, expected to fail
Comment #25
nlisgo commentedComment #26
Ankit.Gupta commentedRerolled patch #9 with Drupal 9.5.x
Comment #27
Ankit.Gupta commentedNeeds Review
Comment #28
nlisgo commentedTest only merge request !2793 failed as expected.
Merge request !2791 needs a review.
Comment #29
philltran commentedReviewed and tested on a Drupal 9.4.x site. The error message is no longer appearing in my watchdog. Thanks.
Comment #31
puregin commentedPatch #26 tested on a Drupal 9.5.x site (PHP 8.1.12). The view renders correctly and the error is no longer being thrown.
Comment #32
cilefen commentedSomeone please write a regression test.
Comment #33
poker10 commentedActually a simple test seems to be already created in the merge request, see #28. However it is not contained in the patch file rerolled in #26.
Comment #34
ppound commentedI believe there are other variables that can be set to "All" at least when using a list field type, around line 752 of ./views/src/Plugin/views/field/EntityField.php
$delta_limit = $this->options['delta_limit'];can return "All" and then create white screens. This can probably be fixed around line 412 of the same fileComment #35
arturopanettaI tested patch #26 on Drupal 9.5.1 and PHP 8.1, it works perfectly.
Comment #36
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Hiding the patch in #26 as it skipped over the MRs
MR 2793 = tests-only
MR 2791 = full patch
Removing tests tag as they were in added in the MR
On Drupal 10.1 with php8.1 on a standard install
I followed the steps in the IS and confirmed the issue still appears
MR 2791 still applies to 10.1
Problem is solved.
Comment #37
quietone commentedI don't see an answer to the question in #34? Setting back to NR for that.
I have also added the IS template, and invite everyone to complete that to help reviewers and committers. Thanks.
Comment #38
lendudeedit: whoops that was a bit too fast!
Updated the IS with steps to reproduce, the issue in #34 is unrelated and needs a new issue with it's own steps to reproduce.
The test looks good, would kinda prefer to a have a functional test for this too, since it's a pretty common scenario to do this and I'm a bit sad that we don't have coverage that would cover this scenario. The unit test hits the right code path for this specific bug, but it would be nice if we had broader coverage for this feature
Comment #39
danchadwick commentedTL;DR: Let's commit this, then open new issue(s) for similar situations.
This issue is the poster child for agility.
- Drupal now requires PHP 8+.
- PHP 8+ causes this bug.
- This bug has a nasty failure mode -- white screen of death.
- This bug occurs frequently; lots of sites are affected by this common configuration.
- The fix is both trivial and low-risk, only restoring the pre-8.0 meaning of the code.
- The fix was posted a year ago.
- Took a year to satisfy the demand for automated tests.
- Finally marked RTBC
- Now issue creep puts it back to Needs Review, expanding the issue beyond the original scope reported and including less frequent, less urgent situations.
If medicine worked this way, we'd still be waiting for the C19 vaccines.
Comment #40
danchadwick commentedWhoops. My post crossed with #38. Restoring status to RTBC as per #38.
Comment #41
lendudeOpened new issue for #34, very easy to reproduce, good find, see #3346748: Entering a non-numeric value for a start row value in 'Multiple field settings' for a views field leads to a fatal error
Comment #42
catchRetrospectively bumping this to critical since it's a fatal error in common configurations.
Committed cbd7cf7 and pushed to 10.1.x. Thanks! also backported to 10.0.x and 9.5.x
Comment #46
catch