Problem/Motivation
Background: https://github.com/mglaman/phpstan-drupal/issues/221
When I see the (newish) deprecated service warning in upgrade status report (on my 8.9.19 site, I get it for our favorite deprecated service, path.alias_manager
), the documentation link is wrong -- specifically, it's missing the last number:
The "path.alias_manager" service is deprecated. Use "path_alias.manager" instead. See https://drupal.org/node/309208.
Correct documentation link, per core.services.yml (is that where the deprecation warning text comes from, or?): https://www.drupal.org/node/3092086
BUT, when I checked my project via drush, the documentation link is there, in full (screenshot)
$ drush upgrade_status:analyze mytheme
My Theme Name, --
Scanned on Fri, 11/05/2021 - 18:10
FILE: web/themes/mytheme/mytheme.theme
STATUS LINE MESSAGE
--------------------------------------------------------------------------------
Check manually 95 The "path.alias_manager" service is deprecated. Use
"path_alias.manager" instead. See
https://drupal.org/node/3092086
Steps to reproduce
Go to upgrade status report on a 8.9.19 site that has a project that uses path.alias_manager
, and scan that project (in my case, it's in our site theme's .theme
file). Then, click the "local scan result" that'll come up in the report.
About me:
- mglaman/phpstan-drupal version 0.12.15
- drupal/upgrade_status version 3.11.0
- drupal/core version 8.9.19
Note: My only example so far is with path.alias_manager
, I'm not sure if it's happening with other deprecated services, because it's the only one I've got. It would be cool if someone could try to reproduce the issue with another deprecated service, of course. Looking at core.services.yml, there are only a few other deprecated services with documentation links (and several of them point to the same documentation link as path.alias_manager).
Here are the two I found that have documentation links other than https://drupal.org/node/3092086
:
- entity.query
- path.alias_storage
Proposed resolution
TL;DR: Probably somewhere here, though I can't figure out how -- but like, it's gotta be, right?...........
upgrade_status/src/ScanResultFormatter.php#L223
More thoughts (feelings?) --
I have no proof, but it feels like the URL is getting truncated somehow?
The link is correct when you analyze via drush, and also, I can't find any mention of "309208" without the 6 at the end, anywhere in Drupal core. (I ran grep -r "309208" web/core/
locally, and, here's a search on GitLab that's the same thing.)
So, after a lot of digging around mglaman/phpstan-drupal, the upgrade_status project, and Drupal core, my guess is that the link is getting truncated. To be clear, while this theory is my best guess, it also sounds quite unlikely 🤷♀️
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#21 | 3247970-21-test-only.patch | 3.18 KB | Gábor Hojtsy |
#20 | 15-test-only-fixed.patch | 3.39 KB | Gábor Hojtsy |
#15 | 15-test-only.patch | 2.11 KB | Gábor Hojtsy |
upgrade-status_deprecated-service-warning_report-page.png | 6.54 KB | alison | |
upgrade-status_deprecated-service-warning_drush.png | 39.91 KB | alison |
Issue fork upgrade_status-3247970
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:
Comments
Comment #2
mglamanI was able to reproduce it here: https://3v4l.org/lWPio
And regex example: https://www.phpliveregex.com/p/Cwc
Comment #3
mglamanUsing this regex seems to fix it:
See (https://drupal.org(.*)).$
The
.\S+
is skipping the last character for some reason.Comment #4
Gábor HojtsyHm, that assumes that there is a character (not even a dot lol), after the issue link. Is this the first one where there is none? Wow.
Comment #5
Gábor HojtsyWell, the dot is swallowing the last character in the string, and here it is a significant character :D The
.$!
should probably be changed to(\.|$)!
or somesuch to allow for either a dot or a direct string end.Comment #6
mglamanOh snap, I see.
The regex assumes punctuation. There isn't any. So the regex is broken. So it's a core bug, technically.
Comment #7
alisonAllowing for with/without a period at the end of the sentence makes sense to me. We could look at whether there's "supposed to be" a period at the end of those deprecation messages, in coding/grammar standards, or we could just do it as @Gábor Hojtsy suggests in #5.
I have a family thing tonight and I gotta run, but I'd love to submit a patch tomorrow if someone doesn't beat me to it -- no hard feelings if someone beats me to it, we all know "I'm definitely going to do this tomorrow" doesn't always work out.
Comment #9
alisonMerge request submitted -- I tested on my own project, the documentation link for "path.alias_manager" is fixed.
I have not tested it with any other deprecated services (with or without documentation links).
Comment #10
mglamanTests pass! Looks good to me, but maybe we should add a test sample that proves that deprecation message is properly reported.
Comment #11
Kristen Pol@mglaman Are there plans to add a test or can this be RTBCed as is?
Comment #12
mglamanI think we probably need a test to verify the regex properly
Comment #13
Kristen PolMoving back for tests per #12.
Comment #14
Gábor HojtsyUpdated a tested message and the expectation that should prove this I think. Once/if that passes, a test only patch would be useful to prove that it otherwise fails and we are good IMHO.
Comment #15
Gábor HojtsyHere is the test changes only.
Comment #16
Gábor HojtsyHm that did not prove it...
Comment #17
Kristen PolMaybe I'm not following, but my understanding is:
1) Regex was eating the last character of the deprecation message when there wasn't a period at the end.
2) We need a test that will show the link extracted by the regex is broken before the code is fixed.
3) If this is correct, you need to test the extracted link and not the full text. i.e. the old regex should cause the link to be like:
so if you check that link is valid, you should get a 404.
Comment #18
Gábor HojtsyI think the last letter would be lost not just missing from the link. As shown in the screenshot in the issue summary too.
This will eat the last character, whatever it is (unescaped period at end of string matches whatever character there is). Then it will be replaced with a literal period. Because it matches to the end of the string, the character matched by the unescaped period would be lost. So I was expecting this simple test change should show it failing. It should not be lost from the link only but from the entire string.
Comment #19
Gábor HojtsyOk the problem with the test is that the bug is in the result formatter which is only used on the UI, so the analyzer test will not find it. We should update the UI test.
Comment #20
Gábor HojtsyOk now this should fail without the fix. #famouslastwords
Comment #21
Gábor HojtsyHm, the MR branch is not up to date. Rerolled the test only.
Comment #22
Gábor HojtsyMeh, I give up. I think the fix is correct regardless of whether we can make the test coverage fit :D
Comment #24
Gábor HojtsySo committed the fix as-is. Thanks all!
Comment #25
Kristen PolAh ha! Glad you sorted it… good work everyone:)