Views pager offset causes fatal error if empty

Created on 12 July 2023, over 1 year ago
Updated 2 November 2023, about 1 year ago

Problem/Motivation

If the views pager offset is an empty string, not a number, a) the views edit page will show an ajax error and b) the rendered view will cause a php Fatal error: TypeError: Cannot assign null to property Drupal\views\Plugin\views\query\QueryPluginBase::$offset of type int.

Of note is that leaving this field blank does not cause an error in Drupal 8 and 9. Therefore, a site may be functioning normally in this configuration, then have this fatal error after upgrade to Drupal 10.

Steps to reproduce

Create a view of Articles or other type, unformatted list of titles with a block or page display.
Edit the pager offset, remove any numeral and save.

πŸ› Bug report
Status

Closed: duplicate

Version

10.1 ✨

Component
ViewsΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States ransomweaver

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

Comments & Activities

  • Issue created by @ransomweaver
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    I tried to reproduce this in a clean Umami install on 11.x.

    Added a view of recipes
    Using the mini pager
    Set the "Offset (number of items to skip)" to an empty value
    Saved the view successfully
    Loaded the view successfully

    Then tried the same with the full pager and got the same results.

    Am I missing a step here? Is there any way to reproduce this on a clean install of does it need to be an updated site?

  • πŸ‡ΊπŸ‡ΈUnited States aangel

    I'm upgrading to 10.1 and encountered this. The workaround that seems to be working for me is to use this local patch (didn't want to fork the issue since this is a complete hack):

    In [project_root]/project/patches, place the code below in ViewsPagerOffset.patch:

    --- a/core/modules/views/src/Plugin/views/query/QueryPluginBase.php
    +++ b/core/modules/views/src/Plugin/views/query/QueryPluginBase.php
    @@ -149,7 +149,12 @@
        * Set an OFFSET on the query, specifying a number of results to skip.
        */
       public function setOffset($offset) {
    -    $this->offset = $offset;
    +    if (is_null($offset)) {
    +      $this->offset = 0;
    +    }
    +    else {
    +      $this->offset = $offset;
    +    }
       }
    
       /**

    In composer, make sure Cameron's patching plugin is installed:
    "cweagans/composer-patches": "^1.7",

    In the extras section, create an entry to apply the local patch:

        "extra": {
            "enable-patching": true,
            "patches": {
                "drupal/core": {
                    "Views pager offset causes fatal error if empty": "project/patches/ViewsPagerOffset.patch"
                }
            },

    Remove core:
    rm -Rf web/core

    Run composer:
    composer update

    You should see something like:

     - Installing drupal/core (10.1.1): Extracting archive
      - Applying patches for drupal/core
        project/patches/ViewsPagerOffset.patch (Views pager offset causes fatal error if empty)

    Of course, finding out what changed between 9.5 and 10.1 and fixing that is the better solution.

  • Open on Drupal.org β†’
    Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    Not currently mergeable.
  • @tobas1996 opened merge request.
  • First commit to issue fork.
  • last update over 1 year ago
    29,457 pass
  • Status changed to Closed: duplicate about 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies
Production build 0.71.5 2024