Problem/Motivation

As discovered in #2802403: Combination of language negotiation and path aliasing can cause a corrupted route cache, 404s the path processors are not working as expected. They are independent of the request that is being processed. Currently this is only visible in case of the alias path processor, which when called in context of X language to process Y language alias will fail:

Given that the current language is EN and we want to process a path /fr/some-alias it will fail and return the alias of path instead
of the path.

Proposed resolution

1. Add the processing request to the request stack and pop it when the processing is done. This would allow all services used during the processing to be specific for the current request. Update the language manger service to return language per request / the current
request from the stack.
2. .. other propositions

Remaining tasks

1. Detect other possible caveats other then the language manager.

User interface changes

None.

API changes

Not sure.

Data model changes

None.

Comments

_Archy_ created an issue. See original summary.

_Archy_’s picture

Status: Needs review » Needs work

The last submitted patch, path-test_failing_alias_processor.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

fubhy’s picture

I just ran across this while working on the GraphQL Module. We are making use of sub-requests to properly resolve contexts from Url objects in our graph. Since our requests all run through /graphql, we have no other option than to use sub-requests to properly set the global contexts used within a variety of internal APIs. The language negotiation, as pointed out by this issue, is one of these and since the request stack is not taken into consideration here, we are always using the negotiated language from the /graphql request which is obviously incorrect.

fubhy’s picture

We solved this temporarily by using the reset() method on the languager manager from within our sub-request.

_Archy_’s picture

Status: Needs work » Needs review
StatusFileSize
new7.22 KB

I have created this patch in the parent issue, but I am posting it here as-well. There it was breaking badly, let's see how it performs now.

Status: Needs review » Needs work

The last submitted patch, 6: path-request_stack_aware_processing-2940036-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

karishmaamin’s picture

Status: Needs work » Needs review
StatusFileSize
new7.22 KB

Re-rolled patch against 9.4.x. Please review

Status: Needs review » Needs work

The last submitted patch, 16: 2940036-16.patch, failed testing. View results

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

arunkumark’s picture

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

Re-rolled the patch to be support for the Drupal 9.5.x

Status: Needs review » Needs work

The last submitted patch, 19: path-process-2940036-19.patch, failed testing. View results

Ankit.Gupta’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.52 KB

Rerolled patch #19 with Drupal 9.5.x

Status: Needs review » Needs work

The last submitted patch, 21: path-process-2940036-21.patch, failed testing. View results

ameymudras’s picture

Issue tags: +Needs tests

@ankit the patch #19 already works for Drupal 9.5.x not sure why you re rolled it again, please include a interdiff so that we can verify what are the changes.

@arun the patch #16 contained supporting tests which have been removed from your patch.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jan kellermann’s picture

StatusFileSize
new817 bytes

We had a similar problem but this patch is much to invasive. For example all admin-menu-links got wrong language prefix because of missing currentLanguage.

You are right that AliasPathProcessor::processInbound() does not handle the given request and the given $path is at this point without language prefix:

 public function processInbound($path, Request $request) {
    $path = $this->aliasManager->getPathByAlias($path);
    return $path;
  }

But the called function getPathByAlias() has an 2nd paramater for language. So you can use:

  public function processInbound($path, Request $request) {
    // Get language from request.
    $lang = \Drupal::service('language_negotiator')->getNegotiationMethodInstance('language-url')->getLangcode($request) ?? NULL;

    $path = $this->aliasManager->getPathByAlias($path, $lang);
    return $path;
  }

Now you can get the path by alias in other languages than current.

Maybe you will try the patch in combination with your tests.

I did test locally with this code:

use Symfony\Component\HttpFoundation\Request;

$pathProcessor = \Drupal::service('path_processor_manager');
$path_de = '/de/lang-de-test';
$path_en = '/en/lang-en-test';

$request = Request::create($path_de);
$processedPath = $pathProcessor->processInbound($path_de, $request);
dpm($processedPath);

$request = Request::create($path_en);
$processedPath = $pathProcessor->processInbound($path_en, $request);
dpm($processedPath);

If you have trouble with fixed "getCurrentLanguage()" (e.g. for language sensitive access checks) then you have to reset() the languageManager and use the requestStack in this situations. But in general - like in this patch suggested - seems to be too much.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

jonhattan’s picture

StatusFileSize
new7.29 KB

Tried this to fix #2801397 with no luck. Here's a reroll of the patch in #21 on main in case it is of interest to someone. Not changing the status since I was not trying to fix this issue.