path.alias_repository service does not use a proper language fallback mechanism

Created on 31 October 2019, about 5 years ago
Updated 19 February 2023, almost 2 years ago

Following is the current language fallback logic used in the path.alias_repository service:

    // Always get the language-specific alias before the language-neutral one.
    // For example 'de' is less than 'und' so the order needs to be ASC, while
    // 'xx-lolspeak' is more than 'und' so the order needs to be DESC.
    $langcode_list = [$langcode, LanguageInterface::LANGCODE_NOT_SPECIFIED];

This logic doesn't take into account where custom/contrib modules may implement hook_language_fallback_candidates_alter() to add/remove fallback candidate languages.

Example of one such contrib module:
Language hierarchy: https://www.drupal.org/project/language_hierarchy

Attaching a patch to user proper fallback mechanism. i.e.:

    // Get list of all languages that current language falls back on.
    $langcode_list = $this->languageManager->getFallbackCandidates([
      'langcode' => $langcode,
      'operation' => 'path_alias',
    ]);
🐛 Bug report
Status

Needs work

Version

9.5

Component
Path 

Last updated 19 days ago

  • Maintained by
  • 🇬🇧United Kingdom @catch
Created by

🇮🇳India dipakmdhrm

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    As a bug this will need a test case.

  • Status changed to Needs review almost 2 years ago
  • 🇬🇧United Kingdom james.williams

    Woah, patches 78 & 79 have taken a completely different approach to all previous patches, with no explanation or interdiff. They reference a service that isn't even in core, but looks like a contrib one (language_fallback.controller)? So we'll need updates about those please (@rzanetti?), otherwise those will have to be ignored, as yes, that approach needs tests (and more).

    But returning to the patch in #69, which is otherwise the 'current' one, that one does include tests. Its tests-only patch shows failures as expected, and the fix+tests patch passes tests. That said, I haven't myself had time to review updates since comment 64, so there are outstanding concerns that might need addressing.

  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States smustgrave

    Reviewing #69

    +      @trigger_error('The language_manager service must be passed to AliasRepository::__construct(), it is required before Drupal 9.1.1. See https://www.drupal.org/node/3108585.', E_USER_DEPRECATED);
    

    1. This doesn't seem like the normal template. But will also need version update.

    Tests look good but would need a 2nd pair of eyes.

  • 🇬🇧United Kingdom james.williams

    @smustgrave Fair point. Which version should this issue be targeting? Should it really be Drupal 10.1 by now? Given the pace of this issue, I'm reluctant to spend time changing the version number in that string when it's only likely to need to change again! I've always wondered, how is that handled on other issues, do they just keep updating such strings every time a new release comes along??

  • 🇺🇸United States smustgrave

    Can look at other example in core for the template wording. But it would be required for Drupal 11.

  • heddn Nicaragua
    +++ b/core/modules/path_alias/src/AliasRepository.php	(revision da61e77ac1a1354030d2e6c0251553effd47d9cc)
    @@ -122,20 +138,29 @@
    +    // hook_tag_path_alias_language_fallback_alter().
    

    I think this should be updated to the following:

    // hook_query_tag_path_alias_language_fallback_alter().

  • 🇩🇪Germany J-Lee 🇩🇪🇪🇺

    @james.williams have found two examples for the wording:

    @trigger_error("The property $name ($service_name service) is deprecated in $class_name and will be removed before Drupal 11.0.0.", E_USER_DEPRECATED);

    @trigger_error('The key-value pair "experimental: true" is deprecated in drupal:10.1.0 and will be removed before drupal:11.0.0. Use the key-value pair "lifecycle: experimental" instead. See https://www.drupal.org/node/3263585 ', E_USER_DEPRECATED);

    Maybe it helps?

  • Status changed to Needs review about 1 year ago
  • 🇬🇧United Kingdom james.williams

    Thanks both. Here are updated patches based on #69, taking into account the feedback from #83 (I used an example from \Drupal\migrate\Plugin\migrate\id_map\Sql which was the first similar one that I found) and #86.

    I've also updated the change record, targeting 10.2.0 (though I don't know if that's possible).

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    30,512 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Custom Commands Failed
  • The Needs Review Queue Bot tested this issue. We recommend that you convert this patch to a merge request .

    Merge requests are preferred over patches. Be sure to hide the old patch files as well (converting an issue to a merge request without other improvements is not recommended and will not receive credit).

  • Status changed to Needs work about 1 year ago
  • 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 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.

  • 🇫🇷France nod_ Lille

    bot was mistaken about the actual problem but it's a valid NW

  • @jameswilliams-0 opened merge request.
  • 🇬🇧United Kingdom james.williams

    Can anyone help me understand/resolve the Nightwatch test failure https://git.drupalcode.org/issue/drupal-3091336/-/jobs/308229 ? I don't understand how this is something these changes could have triggered.

  • 🇺🇸United States smustgrave

    Have you reran it? Nightwatch has been weird this week.

  • Status changed to Needs review about 1 year ago
  • 🇬🇧United Kingdom james.williams

    Oh wow, that was all that was needed. Bizarre. Took two attempts, but there now.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Hiding the patches for clarity now that the fix is in the MR.

    Could the issue summary be updated though. I got it started but not as familiar with the issue to be able to speak on it.

    And as far as your comment

    can well imagine this isn't the "right" thing to do! The changes in PathItem.php replace blocks of code that triggered these messages, reducing them in total, ...

    I don't think that's problem. That property is already there and being used, you're just using it again.

  • Status changed to Needs review about 1 year ago
  • Status changed to RTBC about 1 year ago
  • 🇺🇸United States smustgrave

    All threads have been resolved and issue summary updated to match what's being proposed. Going to mark it but could the MR 5332 be updated to point to 11.x, that's the current development branch and all code has to land there first. Then to be backported. If a separate MR is opened for 11.x can you make note of what is what in the issue summary

  • Pipeline finished with Failed
    about 1 year ago
    Total: 683s
    #48813
  • Pipeline finished with Success
    about 1 year ago
    Total: 876s
    #48812
  • 🇬🇧United Kingdom james.williams

    Thanks! OK, so branch 3091336-alias-repo-service-fallback-d11 / MR !5373 is for the 11.x branch. I've cherry-picked the 3 commits from the already-reviewed MR !5332 (branch 3091336-path.aliasrepository-service-does), which is for the 10.2.x branch.

    The branch 3091336-path.aliasrepository-service-fallback-d11x can be ignored, that was a mistake, sorry. (Can incorrect branches be hidden/deleted?)

    Does the addition of the language manager argument for the alias repository need to be made required now, for that 11.x version? Or is that best done as a follow-up?

  • Pipeline finished with Success
    about 1 year ago
    Total: 667s
    #48832
  • 🇺🇸United States smustgrave

    11.x is the development branch, think of it as the main. Future D10 releases, 10.3 for example, will be tagged off that.

  • 🇺🇸United States xjm

    Closed the old MR.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States xjm

    Posted suggestions for miscellaneous coding standards issues on the merge request. Thanks!

  • Pipeline finished with Success
    about 1 year ago
    Total: 571s
    #50112
  • Status changed to Needs review about 1 year ago
  • 🇬🇧United Kingdom james.williams

    Thanks for that! I've committed fixes for all those bits of feedback.

  • Pipeline finished with Success
    about 1 year ago
    Total: 597s
    #50124
  • Status changed to RTBC about 1 year ago
  • 🇺🇸United States smustgrave

    Appears all threads have been addressed from @xjm

  • 🇺🇸United States xjm

    @smustgrave This is one of those cases where it'd be really helpful for you to do your own careful re-review rather than auto-RTBCing when "all committer feedback is addressed".

    I feel weird committing this since I made so many suggestions. It got a bit out of hand. 🙂 I probably should have just given the high-level feedback of "remember your void typehints and 'the'". So another set of eyes reviewing not only that my changes were added, but that each was a correct change and made sense, would be really useful.

  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States xjm

    Setting back to NR to try to get some close review of my suggestions and @james.williams' fixes and that it all made sense, since no other committers have taken this up for commit in the past three weeks either.

  • Status changed to Needs work 12 months ago
  • 🇺🇸United States smustgrave

    Left a few small changes.

    I requested push access but still don't seem to be able to run the test only feature. @James.williams do you have the ability to so we can all see. Else I can run locally.

  • Pipeline finished with Failed
    12 months ago
    Total: 280s
    #68848
  • Pipeline finished with Canceled
    12 months ago
    Total: 105s
    #71447
  • Pipeline finished with Failed
    12 months ago
    Total: 219s
    #71449
  • Pipeline finished with Failed
    12 months ago
    Total: 1292s
    #71462
  • Pipeline finished with Failed
    12 months ago
    Total: 1043s
    #71490
  • Pipeline finished with Failed
    12 months ago
    Total: 1157s
    #71505
  • 🇬🇧United Kingdom james.williams

    Thanks; I've addressed remaining feedback where I can.

    What should I do about the Functional Javascript test failure, which is reporting that (at least) one additional database query has been performed in Drupal\Tests\standard\FunctionalJavascript\StandardPerformanceTest::testAnonymous ? Is there any way to get reports/assets from Drupal CI to see which is the extra query, or does it have to be investigated locally? I had a go at trying to just spot the extra query from just tracing the code statically by eye, but I couldn't find it that way.

    As for the test-only failure, I've triggered the 'Test-only changes' item under the 'DEFAULT: PHP 8.2 MySQL 8' job - but should I be using the 'DEFAULT: Test-only (PHP 8.2 MySQL 8)' test job itself? They might well be triggering the same thing; I can't tell!

  • Status changed to Needs review 12 months ago
  • heddn Nicaragua

    A rebase should be all that is needed to fix the counts.

  • Pipeline finished with Failed
    12 months ago
    Total: 603s
    #71589
  • 🇬🇧United Kingdom james.williams

    The rebase didn't fix the counts. I've spent several hours setting up chromedriver etc to be able to run the functional javascript tests locally, and found it's because the 'path_alias_language_fallback' tag is added to the alias lookup query, when looking up the incoming path. So hook_query_TAG_alter() is invoked, which includes querying the 'cache_bootstrap' database table for the 'module_implements' and 'hook_info' cache entries, i.e. which modules implement which hooks, at the point of early bootstrapping. To me, that seems a reasonable addition, as that cache entry will almost certainly need looking up at some point for users on other common pages anyway? I could be wrong. (FWIW, Berdir had done some performance testing up in comment #53 and found the performance hit was very small.)

    On the belief that this is OK to do, I'll increase the count of allowed queries to accommodate this fix.

  • Pipeline finished with Failed
    12 months ago
    Total: 526s
    #71742
  • Pipeline finished with Failed
    12 months ago
    #73556
  • Pipeline finished with Success
    12 months ago
    Total: 526s
    #73597
  • Pipeline finished with Failed
    12 months ago
    Total: 524s
    #73602
  • Pipeline finished with Failed
    11 months ago
    Total: 774s
    #73621
  • Pipeline finished with Success
    11 months ago
    #73652
  • 🇬🇧United Kingdom james.williams

    I've now avoided the need for monolingual sites to perform the extra queries, and run the test-only job. Properly ready for review again!

  • Status changed to RTBC 11 months ago
  • 🇺🇸United States smustgrave
    There were 2 failures:
    1) Drupal\Tests\path_alias\Kernel\AliasLanguageFallbackTest::testLookupByAlias
    The Afrikaans path alias is returned if we specify English to the alias repository and Afrikaans is a valid fallback candidate for English.
    Failed asserting that null matches expected '/user/1'.
    /builds/issue/drupal-3091336/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:94
    /builds/issue/drupal-3091336/core/modules/path_alias/tests/src/Kernel/AliasLanguageFallbackTest.php:71
    /builds/issue/drupal-3091336/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    2) Drupal\Tests\path_alias\Kernel\AliasLanguageFallbackTest::testLookupBySystemPath
    The Afrikaans path alias is returned if we specify English to the alias repository and Afrikaans is a valid fallback candidate for English.
    Failed asserting that null matches expected '/test-login-alias'.
    /builds/issue/drupal-3091336/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:94
    /builds/issue/drupal-3091336/core/modules/path_alias/tests/src/Kernel/AliasLanguageFallbackTest.php:103
    /builds/issue/drupal-3091336/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    FAILURES!
    Tests: 2, Assertions: 8, Failures: 2.
    

    Thanks for running test-only job. Not sure why push access broke on this single issue.

    Reading the threads believe all feedback has been addressed.

  • mei2020 changed the visibility of the branch 3091336-path.aliasrepository-service-does to active.

  • Status changed to Needs work 10 months ago
  • 🇳🇿New Zealand quietone

    I'm triaging RTBC issues . I read the IS, the comment, the MR and the CR. I didn't find any unanswered questions.

    @james.williams, thank you for getting this issue to RTBC. I found your comments were always helpful and explained the changes and referred to the review that requested a change.

    Starting with the CR, that needs to be updated, including the title. The CR should include before and after code samples. The title is to be a statement of the change without the 'should', this is a new requirement. Searching existing change records provides some examples that should help; https://www.drupal.org/node/3387233 , https://www.drupal.org/node/3014688 . I've added the tag for change record updates.

    I read the CR, not a code review, and I didn't see anything that I thought should change.

    I think all the core gates have been completed here.

    Finally, let's improve the title of this issue so it says something about the fix, not the problem. Also, what is a 'proper' mechanism anyway? :-) Maybe, "Ensure path alias repository returns the correct fallback language'?

    So, just a few things.

  • Status changed to Needs review 10 months ago
  • 🇬🇧United Kingdom james.williams

    OK, thanks @quietone - I've updated this issue's title, and the CR: https://www.drupal.org/node/3108585

    "what is a 'proper' mechanism anyway?" - haha, fair question! I think just supporting a sane way of altering language fallbacks: via the existing hook_language_fallback_candidates_alter() hook (which the usual entity repository service respects, but not path.alias_repository service, until this change).

  • 🇬🇧United Kingdom james.williams

    james.williams changed the visibility of the branch 3091336-path.aliasrepository-service-does to hidden.

  • 🇬🇧United Kingdom james.williams

    james.williams changed the visibility of the branch 3091336-path.aliasrepository-service-fallback-d11x to hidden.

  • Status changed to RTBC 10 months ago
  • 🇺🇸United States smustgrave

    CR and title read well.

  • Status changed to Needs work 9 months ago
  • 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.

  • First commit to issue fork.
  • 🇮🇳India sakthi_dev

    Rebased with 11.x by resolving the conflicts.

  • Pipeline finished with Failed
    9 months ago
    Total: 191s
    #117626
  • Status changed to Needs review 9 months ago
  • 🇮🇳India adwivedi008

    MR at #123 seems fine but as on comparison we can see a lot of changes at the MR
    Moving the issue to needs review as its previous status was RTBC over #120

    Let's wait for some more reviews and then move this to RTBC

    RTBC+ From my side

  • Status changed to Needs work 9 months ago
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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.

  • Pipeline finished with Failed
    9 months ago
    Total: 522s
    #118072
  • Pipeline finished with Success
    9 months ago
    Total: 525s
    #118105
  • Status changed to Needs review 9 months ago
  • 🇬🇧United Kingdom james.williams

    Fixed the tests... changes to the baseline for phpstan had been missed from the rebase, and the extra assertion about the number of queries on user pages was no longer helpful (presumably work on core elsewhere had reduced the number of queries, which is a good sign!), so I removed it.

  • Status changed to RTBC 9 months ago
  • 🇺🇸United States smustgrave

    restoring status from before

  • Status changed to Needs work 9 months ago
  • 🇬🇧United Kingdom catch

    One comment on the MR, but also the issue summary seems very out of date with what's going on in the MR - it's changing the form handling and the changes to alias repository are different to what's in the issue summary too.

  • 🇬🇧United Kingdom james.williams

    Thanks; I've now updated the issue summary.

    @catch I'm not sure what you meant about form handling, as there's no mention of forms in the MR - but I'm guessing perhaps you were referring to the changes in the PathItem class, so I've added a specific mention of them in the proposed resolution. Otherwise, I'm not all that sure what you feel is specifically wrong with the issue summary? Of course I can well believe there's something needing more explanation!

  • Pipeline finished with Failed
    9 months ago
    #135254
  • Pipeline finished with Success
    9 months ago
    Total: 6556s
    #135271
  • Status changed to Needs review 9 months ago
  • 🇬🇧United Kingdom james.williams

    Resolved that last thread, moving the special handling for path aliases into the path_alias module.

    (And for any language_hierarchy users, I've pushed a fix to respect that to its 2.x branch.)

    :crossed_fingers:

  • Status changed to Needs work 8 months ago
  • 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.

  • Pipeline finished with Failed
    8 months ago
    #161415
  • Pipeline finished with Failed
    8 months ago
    Total: 205s
    #161417
  • Pipeline finished with Success
    8 months ago
    Total: 1668s
    #161422
  • Status changed to Needs review 8 months ago
  • 🇬🇧United Kingdom james.williams

    Resolved issues in MR (resolved merge conflict + added strict typing for new class files). Tests pass, and tests-only job fails as expected. Back to needs review; everything should be answered. Really looking forward to this finally getting over the last hurdle(s). Core development is one big exercise in persistance!

  • Status changed to Needs work 7 months ago
  • 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.

  • Pipeline finished with Failed
    7 months ago
    Total: 181s
    #177004
  • Pipeline finished with Success
    7 months ago
    Total: 579s
    #177013
  • Status changed to Needs review 7 months ago
  • 🇬🇧United Kingdom james.williams

    Updated MR to be mergeable again. And of course some coding standards have tightened since the last update, so added a couple of trailing commas accordingly. So many hurdles, many of which are purely down to the amount of time this has sat waiting :sob: Very much looking forward to getting this one over the line eventually, I hope.

    Though of course I realise we're now at beta for 11.0... so does that mean we now need to adjust the change record & deprecation to target 11.1 & 12 instead of 10.3 & 11? :despair:

  • Status changed to Needs work 7 months ago
  • 🇺🇸United States smustgrave

    Left some small nitpicky stuff. But deprecation believe needs to be updated + the associated change record.

  • Pipeline finished with Canceled
    7 months ago
    Total: 452s
    #185769
  • Pipeline finished with Success
    7 months ago
    Total: 610s
    #185779
  • Status changed to Needs review 7 months ago
  • 🇬🇧United Kingdom james.williams

    I've resolved each of those and updated the change record.

    I feel like there should really be a better process for chasing deprecation versions for long-running issues like this. All too often here it's been so long between reviews (I'm not complaining about that btw), and so having to manually update the versions just to chase that game is incredibly tedious :( Are there any efforts anywhere for improving that process perhaps?

  • 🇪🇸Spain google01

    Patches don't apply work on 10.3.x

  • 🇧🇪Belgium RandalV

    Hi @google01,

    Merge request definitely applies to 10.3.x.

    The contents of this: https://git.drupalcode.org/project/drupal/-/merge_requests/5373.diff
    Should be downloaded and placed in a local folder (e.g. YOUR_PROJECT/patches/core/3091336.patch), make sure there's an empty line at the end, and then add `patches/core/3091336.patch` in your composer patches list.

  • 🇺🇸United States smustgrave

    Left a comment on MR. Sorry for taking so long.

  • 🇩🇪Germany J-Lee 🇩🇪🇪🇺

    I have left a suggestion so that someone with write permission can apply it directly to MR.

  • Pipeline finished with Success
    4 months ago
    Total: 722s
    #258013
  • Status changed to RTBC 4 months ago
  • 🇺🇸United States smustgrave

    Re-reviewed from before and believe all feedback has been addressed

  • 🇬🇧United Kingdom catch

    Couple of comments on the MR.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 153s
    #329282
  • Status changed to Needs review about 1 month ago
  • 🇬🇧United Kingdom james.williams

    Thanks @catch ... ready for review again... :doubly_crossed_fingers:

  • Pipeline finished with Success
    about 1 month ago
    Total: 780s
    #329291
Production build 0.71.5 2024