Problem/Motivation

The PagerManager service persists maxPagerElementId across requests in kernel tests, causing subsequent requests to use a different pager element ID than expected. This makes the 'page' query parameter not correspond to the correct pager element.

This was noticed in #3588363: Convert some tests in Drupal\FunctionalTests namespace to kernel tests and a workaround was added in \Drupal\KernelTests\Core\Entity\RevisionVersionHistoryTest::resetPagerState

Steps to reproduce

Proposed resolution

Remaining tasks

Determine the best approach here

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3609436

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

joachim’s picture

This is going to affect persistent servers too.

catch’s picture

We could use the cache.memory bin for this, and then reset the cache.memory bin after each kernel test drupalGet() request maybe?

For persistent servers we're probably going to need some kind of request-aware memory cache backend - some things should be per-request but not everything. But going from cache.memory to that theoretically new backend would be changing a service name then.

mstrelan’s picture

Status: Active » Needs review

So apparently symfony has a ResettableServicePass that is designed to reset this sort of thing. I reasoned with Claude about this and we came up with this approach. In runtime code we call reset in DrupalKernel::terminate. That's not called by kernel tests so we call it from a new HttpKernelTestBrowser class, which coincidentally I've also introduced in #3566881: Add a submitForm() method to HttpKernelUiHelperTrait. Then we just need to tag services that need to be reset and implement ResetInterface, which many services already do.

The test conversion here is cherry-picked from #3588363: Convert some tests in Drupal\FunctionalTests namespace to kernel tests, we don't need to review it here. The main thing it doesn't need to reset the pager state itself.

Also note the ResettableServicePass moves from symfony/http-kernel to symfony/dependency-injection in symfony 8.1.

mstrelan’s picture

Pushed a commit to use an event subscriber instead of resetting this in two places. The testbot is not kind to me today. FWIW symfony resets this in kernel boot, but that won't help us with multiple requests in kernel tests.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

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