DivisionByZeroError: Division by zero in Drupal\Core\Pager\Pager->setTotalPages()

Created on 8 March 2024, 6 months ago
Updated 4 July 2024, 2 months ago

Problem/Motivation

By doing a search, when you choose to display all the items (items_per_page=All). This error occurs.

DivisionByZeroError: Division by zero in Drupal\Core\Pager\Pager->setTotalPages() (line 78 of core/lib/Drupal/Core/Pager/Pager.php).

Drupal\Core\Pager\Pager->__construct('24', 0, 0) (Line: 56)
Drupal\Core\Pager\PagerManager->createPager('24', 0, 1) (Line: 232)
Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData->getTotalResults() (Line: 205)
Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm->updateTempstoreData(Array) (Line: 657)
Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm->viewsForm(Array, Object) (Line: 111)
Drupal\views\Form\ViewsFormMainForm->buildForm(Array, Object, Object, Array) (Line: 172)
Drupal\views\Form\ViewsForm->buildForm(Array, Object, Object, Array)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('views_form_chirequien_page_1', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 224)
Drupal\Core\Form\FormBuilder->getForm(Object, Object, Array) (Line: 2262)
Drupal\views\Plugin\views\display\DisplayPluginBase->elementPreRender(Array)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725 โ†’ ', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 859)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 421)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
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(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->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: 53)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Set the 'Items per page' filter

Select 'All'

Apply

Proposed resolution

Check the limit value to avoid dividing by 0

Remaining tasks

Validate the patch

๐Ÿ› Bug report
Status

Postponed: needs info

Version

11.0 ๐Ÿ”ฅ

Component
Renderย  โ†’

Last updated 1 day ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium emulamba

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @emulamba
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium emulamba
  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot โ†’ tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request โ†’ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • Status changed to Postponed: needs info 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cilefen

    This does not meet the requirements of a critical issue.

    views_bulk_operations is in the stack trace. Is this reproducible without views_bulk_operations?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia saurabh rawat

    saurabh rawat โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia saurabh rawat

    saurabh rawat โ†’ changed the visibility of the branch 3426603-divisionbyzeroerror-division-by to hidden.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia saurabh rawat

    saurabh rawat โ†’ changed the visibility of the branch 3426603-divisionbyzeroerror-pager to hidden.

  • Pipeline finished with Success
    6 months ago
    Total: 579s
    #125943
  • Status changed to Needs review 6 months ago
  • Status changed to Postponed: needs info 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Was previously tagged for steps to reproduce which are still needed.

    What research was done? How come that value is getting set to 0? Putting a check like this could mask a larger problem.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States FizCS3 Denver

    I've just come across a similar issue...
    For me, was in Layout Builder, "Add Block" of a predefined View display block, and accidentally entered "00" (instead of "99") into the "items per block" field and clicked the Update button. Nothing happened and it kept me on the Configure Block modal. Turns out it threw a similar error to the system log when I looked there, which my trace starts with:

    DivisionByZeroError: Division by zero in Drupal\Core\Pager\Pager->setTotalPages() (line 78 of /var/www/html/web/core/lib/Drupal/Core/Pager/Pager.php)
    
    #0 /var/www/html/web/core/lib/Drupal/Core/Pager/Pager.php(51): Drupal\Core\Pager\Pager->setTotalPages('5', '00')
    #1 /var/www/html/web/core/lib/Drupal/Core/Pager/PagerManager.php(56): Drupal\Core\Pager\Pager->__construct('5', '00', 0)
    #2 /var/www/html/web/core/modules/views/src/Plugin/views/pager/SqlBase.php(333): Drupal\Core\Pager\PagerManager->createPager('5', '00', 0)
    #3 /var/www/html/web/core/modules/views/src/Plugin/views/query/Sql.php(1551): Drupal\views\Plugin\views\pager\SqlBase->updatePageInfo()
    #4 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1441): Drupal\views\Plugin\views\query\Sql->execute(Object(Drupal\views\ViewExecutable))
    #5 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1469): Drupal\views\ViewExecutable->execute(NULL)
    ...

    The above patch makes sense to me, which contains a very reasonable validation of the $limit variable to assure it isn't zero.
    I applied the patch to D10.2.5 and fixes my issue, of user error causing an unnecessarily bad system error.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium emulamba
Production build 0.71.5 2024