Problem/Motivation

The query extender PagerDefault doesn't check if there are already global defined pagers. The class starts an own counting of pagers by using static $maxElement = 0;.
If you've already defined pagers by pager_default_initialize() the query extender will overwrite them as soon as the query is executed.

Proposed resolution

Get rid of static $maxElement = 0; and use the global variable $pager_page_array in ensureElement() to ensure an unique pager id is used for the query extender.

Remaining tasks

Clarify if there are cases in which this handling could lead to unexpected errors.

User interface changes

None

API changes

No real API changes, but the signature of the class PagerDefault will change a bit as static $maxElement = 0; is removed.

Comments

Status: Needs review » Needs work

The last submitted patch, pager-QueryExtender-fix.patch, failed testing.

das-peter’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
StatusFileSize
new3.22 KB
new1.44 KB
new3.31 KB

Blargh, sloppy work. However, an issue is always a good reminder. ;)
Here comes the enhanced version for D8 and D7 as well as tests.
D8-pager-QueryExtender-fix-1857048-2-test-only.patch expected to fail as it only contains the tests without the fix.
D7-pager-QueryExtender-fix-1857048-2-do-not-test.patch contains the fix as well as the new test.

Status: Needs review » Needs work

The last submitted patch, D8-pager-QueryExtender-fix-1857048-2-test-only.patch, failed testing.

das-peter’s picture

Oh I missed the fact that entity query makes its own thing when using the method pager(). Patches adjusted.

Same as before the test-only patch is expected to fail.
D7 patch locally passes the, so far, relevant tests.

Status: Needs review » Needs work

The last submitted patch, D8-pager-QueryExtender-fix-1857048-4-test-only.patch, failed testing.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.phpundefined
@@ -87,14 +80,20 @@ public function execute() {
-      $this->element = self::$maxElement++;
+      global $pager_page_array;

After some discussion we came to the conclusion that the pager ID should be injected, so basically the other way round.

+++ b/core/modules/system/lib/Drupal/system/Tests/Database/SelectPagerDefaultTest.phpundefined
@@ -169,5 +169,24 @@ function testElementNumbers() {
+    $this->assertEqual(count($pager_total_items), ($pager_count + 1), t('Pager query #4 registered its own pager.'));
+    $this->assertEqual($pager_total_items[$max_key], 333, t('Pager query #4 did not touch other defined pagers.'));

I think we musn't use t() functions on new assertion messages.

das-peter’s picture

Status: Needs work » Needs review
StatusFileSize
new4.14 KB

As mentioned by Daniel here comes a solution the other way around.
Less code changes more test assertions.
But for now only for D8, if approach is approved I'll create the related D7 patch.

dawehner’s picture

+++ b/core/includes/pager.incundefined
@@ -118,6 +119,11 @@ function pager_default_initialize($total, $limit, $element = 0) {
+  // Ensure the query extender counter doesn't interfere.
+  if (PagerSelectExtender::$maxElement <= $element) {
+    PagerSelectExtender::$maxElement = $element + 1;

This is way better then before!

+++ b/core/modules/system/lib/Drupal/system/Tests/Pager/PagerTest.phpundefined
@@ -69,6 +70,32 @@ function testActiveClass() {
+    // Test an equal value.
...
+    // Test a bigger step.
...
+    // Test a lower element number.

This seems to be everything you could test.

das-peter’s picture

Component: other » database system

As waving with my hands won't be enough to get attention, I move this to a more popular component :D

das-peter’s picture

Status: Needs review » Needs work

The last submitted patch, 7: D8-pager-QueryExtender-fix-1857048-7.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

Issue summary: View changes
Issue tags: - +Needs reroll
quietone’s picture

Issue tags: +Bug Smash Initiative

Add tag.

karishmaamin’s picture

Status: Needs work » Needs review
StatusFileSize
new3.41 KB

Re-rolled patch against 9.4.x

ankithashetty’s picture

Version: 9.3.x-dev » 9.4.x-dev
Issue tags: -Needs reroll
StatusFileSize
new3.44 KB
new4.37 KB

Fixed custom command errors and updated deprecated codes, thanks!

ankithashetty’s picture

StatusFileSize
new4.37 KB

Attaching a valid interdiff file, thanks!

The last submitted patch, 25: 1857048-25.patch, failed testing. View results

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new252 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.