Problem/Motivation

If you use the "Override number of items to display in contextual filter" option inside Views contextual filter you'll get LogicException: Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata. in Drupal\Core\Render\Renderer->doRender() (line 542 of core/lib/Drupal/Core/Render/Renderer.php).

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Comments

lauriii created an issue. See original summary.

vincenzodb’s picture

Broken also in 8-rc1

vincenzodb’s picture

morbus iff’s picture

Priority: Normal » Major

This is broken in 8.x RC2 and ALSO affects the shipped "Archive" view:

1. Install Drupal 8.x RC2.
2. Make some nodes.
3. Enable the "Archive" view.
4. Go to /archive.

RESULT: White screen of death and the stated LogicException in the watchdog.

To fix the core view, one needs to uncheck the "Override number of items to display in contextual filter" in the filter.

catch’s picture

Issue tags: +rc target

This might be critical, definitely RC target.

catch’s picture

Priority: Major » Critical
Issue tags: -rc target

meh.

dawehner’s picture

Looking at some test coverage for now.

dawehner’s picture

Status: Active » Needs review
Issue tags: +D8 Accelerate
StatusFileSize
new7.24 KB

There we go

Status: Needs review » Needs work

The last submitted patch, 8: 2589703-8.patch, failed testing.

alexpott’s picture

+++ b/core/modules/views/src/Plugin/views/style/DefaultSummary.php
@@ -37,7 +37,7 @@ protected function defineOptions() {
-      $this->view->setItemsPerPage(intval($this->options['items_per_page']));
+//      $this->view->setItemsPerPage(intval($this->options['items_per_page']));

Looks unintentional

dawehner’s picture

Looks unintentional

Oh yeah, well the other test coverage already proves that something is going on wrong

dawehner’s picture

For this particular usecase we already vary by URL due to the usage of the arguments/->url cache context.
Given that its save to not deal with cache keys/contexts in ViewExecutable::setItemsPerPage()
Maybe we want to add a parameter back which allows callers to not deal with cache keys?

geertvd’s picture

Status: Needs work » Needs review
StatusFileSize
new6.36 KB
new7.17 KB
new3.44 KB

Can't we just do the same as ViewExecutable::setCurrentPage() is doing, and check if the element is already pre rendered?

The last submitted patch, 13: 2589703-13-test.patch, failed testing.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

#14 works for me. RTBC - looks great!

dawehner’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/ViewExecutable.php
@@ -553,7 +553,11 @@ public function getItemsPerPage() {
+    // Check whether the element is pre rendered. At that point, the cache keys
+    // cannot longer be manipulated.
+    if (empty($this->element['#pre_rendered'])) {
+      $this->element['#cache']['keys'][] = 'items_per_page:' . $items_per_page;
+    }

Should we provide some unit test coverage for this behaviour? We would though need to apply the same fixes to setOffset and setCurrentPage

The last submitted patch, 8: 2589703-8.patch, failed testing.

The last submitted patch, 13: 2589703-13-test.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new11.46 KB
new4.51 KB

There we go.

dawehner’s picture

There we go.

Status: Needs review » Needs work

The last submitted patch, 19: 2589703=19.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new11.89 KB
new3.17 KB

Seriously, testbot, patches should be allowed to be treated as if they would be equal.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC - Looks great to me!

The last submitted patch, 19: 2589703=19.patch, failed testing.

The last submitted patch, 8: 2589703-8.patch, failed testing.

The last submitted patch, 13: 2589703-13-test.patch, failed testing.

catch’s picture

+++ b/core/modules/views/src/Tests/Plugin/StyleSummaryTest.php
@@ -0,0 +1,76 @@
+    for ($i = 0; $i < 5; $i++) {
+      for ($j = 0; $j < 5; $j++) {
+        $this->entities[] = $entity = EntityTest::create([
+          'name' => 'Entity 1',
+          'type' => 'type' . $i,
+        ]);
+        $entity->save();
+      }
+    }
+  }

This could do with a comment - why do we need 5 of each? And why do they all have the same name/label?

dawehner’s picture

StatusFileSize
new816 bytes
new11.99 KB

Good old numeric code:
($i * 5 + $j)

catch’s picture

s/node types/entity types but that's fixable on commit.

dawehner’s picture

If you correct it, please use '/entity bundles/

catch’s picture

doh, yes.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed 349b678 on 8.0.x
    Issue #2589703 by dawehner, geertvd: Override number of items to display...

  • catch committed 349b678 on 8.1.x
    Issue #2589703 by dawehner, geertvd: Override number of items to display...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.