Active
Project:
Drupal core
Version:
main
Component:
phpunit
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 Aug 2026 at 07:52 UTC
Updated:
31 Aug 2026 at 09:35 UTC
Jump to comment: Most recent
Since #2613044: Requests are pushed onto the request stack twice, popped once, the request stack is managed with the following logic (copied from core.services.yml):
# Drupal pushes to the request stack in DrupalKernel::preHandle(), called
# from KernelPreHandle::handle(). Drupal pops main requests in
# DrupalKernel::terminate() and sub requests in KernelPreHandle::handle().
This does not work for the requests generated by KernelTestBase::drupalGet(), however. They are pushed in DrupalKernel::preHandle(), but DrupalKernel::terminate() never runs as part of the test.
You would expect
$this->assertEquals('/', \Drupal::request()->getRequestUri());
$this->drupalGet('/banana');
$this->assertEquals('/', \Drupal::request()->getRequestUri());
to pass in a kernel test. It will fail, however, on the second assertion because the "current" request URI will still be /banana.
?
-
-
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
Comment #3
tstoecklerAdded a quick MR with the basic test coverage from the issue summary.
Not sure how to solve this. We could add a
pop()todrupalGet()directly, but that would still leave this issue if people do$this->getSession()->visit()"manually". I guess we probably want to discourage that generally, but still maybe not great to pollute the request stack in that case? So alternatively we could add an overriddenHttpKernelBrowserwhich pops the request at the end ofdoRequest()?Comment #4
nitinkumar_7 commentedThe regression test looks good and correctly covers the reported request-stack pollution after drupalGet().
Comment #5
nitinkumar_7 commentedOne minor suggestion: instead of asserting the hard-coded / URI, could we capture the original request and assert that it is still the current request after drupalGet()?
$original_request = \Drupal::request();
$this->drupalGet('/system-test/main-content-handling');
$this->assertSame($original_request, \Drupal::request());
This would make the test more directly verify that the original request is restored, rather than only checking its URI.