Drush sets request with "/" path, but it is not a frontpage.
Describe the bug Drush prepares request in the next way:
// Drupal 10
$request = Request::createFromGlobals();
Which leads to:
$request->getPathInfo() === '/';
The same time:
$pathMatcher->isFrontPage() === FALSE;
It could lead to bad cache data in caches using contexts ["url.page", "url.page.is_front"];
See https://www.drupal.org/project/drupal/issues/3545715
To Reproduce
See https://www.drupal.org/project/drupal/issues/3545715
Expected behavior
It open question should drush scripts be executed as a frontpage request or not.
If yes, "$pathMatcher->isFrontPage()" should return TRUE. If no, there shouldn't be any request in request stack or request should lead to some "/drush" fake path.
System Configuration
| Q | A |
|---|---|
| Drush version? | 13.x |
| Drupal version? | 11.x/10.x |
| PHP version | 8.x |
| OS? | Docker/Linux |
Should drush scripts be executed as a frontpage request or not.
Yes, thats a good question. My initial reply is that Drush has no notion of a path or anything http so the question is invalid. It is up to Drupal to handle CLI requests properly, and not assume all requests are web requests. Thanks for filing that d.o. issue.
This is a bit similar to #6350 which was also just filed. I'm inclined to wait for Drupal fixes for these, but lets please discuss.
Yes, I agree that Drush should has no notion of a path or anything http. However Drupal doesn't work with empty request stack, so I see some workaroud in Drush code that sets request (and in this way a path too)
https://github.com/drush-ops/drush/blob/cdcedee6808ed43124c635203b9248a07249ce78/src/Boot/DrupalBoot8.php#L108
if (method_exists(Request::class, 'create')) {
// Drupal 9
$request = Request::create($uri, 'GET', [], [], [], $server);
} else {
// Drupal 10
$request = Request::createFromGlobals();
}
Having empty request stack or some '<nolink>' fake path/route would avoid having "/" path, that is the same to frontpage one.