Problem/Motivation
Since #3496369: Multiple load path aliases without the preload cache the Redirect module tests have been failing. Specifically \Drupal\Tests\redirect\Functional\GlobalRedirectTest::testRedirects when it asserts that 'Test-node' will be redirected to 'test-node'
Steps to reproduce
Run the test
Proposed resolution
The problem was caused by the removal of the AliasManager cache and how the static cache works on \Drupal\path_alias\AliasManager::getPathByAlias(). In head this does:
// Look for path in storage.
if ($path_alias = $this->pathAliasRepository->lookupByAlias($alias, $langcode)) {
$this->lookupMap[$langcode][$path_alias['path']] = $alias;
return $path_alias['path'];
}
which results in the node/1 path having the alias Test-node in the redirect test. It should be
// Look for path in storage.
if ($path_alias = $this->pathAliasRepository->lookupByAlias($alias, $langcode)) {
$this->lookupMap[$langcode][$path_alias['path']] = $path_alias['alias'];
return $path_alias['path'];
}
which would result in node/1 path having the correct alias test-node.
Remaining tasks
Fix alias manager to store the correct alias and add missing test coverage to core.
User interface changes
None
Introduced terminology
N/a
API changes
None
Data model changes
None
Release notes snippet
N/a
Issue fork drupal-3567086
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:
- 3567086-removal-of-path
changes, plain diff MR !14308
Comments
Comment #3
alexpottThis is going to be fun...
is case sensitive... so this change would mean that the lookupMap is not going to be a good cache if the alias case is different from the case in the URL. ugh.
Comment #4
berdirNot sure I get the full picture yet, but does performance really matter? This is very unlikely to happen much in practice, maybe if you manage to create an alias with uppercase characters and then fix it.
If you have redirect, it will then redirect away, and I wouldn't expect that getPathByAlias() is called that often for the same alias.
Based on debugging this a bit, the initial lookup is even part of the router cache, it's then only called for parents and so on for the breadcrumb and they're all unique calls from what I see with my example on umami.
leaving at needs review for now, not sure if we want a more explicit test for this to assert what's used for the return value, could copy testGetPathByAliasMatch() and simulate that. Probably don't want to test the static cache as we know that won't work.
Comment #5
alexpottComment #6
alexpottI agree I think @berdir you are right this fix is fine for the issue found by the redirect tests. However while testing this out I've discovered another issue - \Drupal\path_alias\AliasPrefixList is case sensitive and it should not be. This means when you make a request for nOde/1 and have an alias for node/1 it does not behave as it should. Going to open a separate issue.
Will try an devise a test for this change that would fail on HEAD without the redirect module in play.
Comment #7
john.oltman commentedI noticed this yesterday while testing an 11.2 to 11.3 upgrade. Thank you @alexpott and @berdir for your work on this, the MR fixes the redirect issue.
Comment #8
berdirLooks good to me, did run the test locally and verified it fails. Tagging since this is required to fix redirect tests on 11.3.
Comment #10
catchCommitted/pushed to main, 11.x and 11.3.x, thanks!