Page MenuHomePhabricator

Wikimedia\Assert\ParameterTypeException: Bad value for parameter $target: must be a LinkTarget|PageReference when viewing Special:TopicSubscriptions (caused by section name longer than 255 bytes)
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
labels.normalized_message
[{reqId}] {exception_url}   Wikimedia\Assert\ParameterTypeException: Bad value for parameter $target: must be a MediaWiki\Linker\LinkTarget|MediaWiki\Page\PageReference
error.stack_trace
from /srv/mediawiki/php-1.41.0-wmf.24/vendor/wikimedia/assert/src/Assert.php(105)
#0 /srv/mediawiki/php-1.41.0-wmf.24/includes/linker/LinkRenderer.php(173): Wikimedia\Assert\Assert::parameterType(array, NULL, string)
#1 /srv/mediawiki/php-1.41.0-wmf.24/extensions/DiscussionTools/includes/TopicSubscriptionsPager.php(82): MediaWiki\Linker\LinkRenderer->makeLink(NULL, string)
#2 /srv/mediawiki/php-1.41.0-wmf.24/includes/pager/TablePager.php(201): MediaWiki\Extension\DiscussionTools\TopicSubscriptionsPager->formatValue(string, NULL)
#3 /srv/mediawiki/php-1.41.0-wmf.24/includes/pager/IndexPager.php(550): TablePager->formatRow(stdClass)
#4 /srv/mediawiki/php-1.41.0-wmf.24/includes/pager/IndexPager.php(587): IndexPager->getRow(stdClass)
#5 /srv/mediawiki/php-1.41.0-wmf.24/includes/pager/TablePager.php(112): IndexPager->getBody()
#6 /srv/mediawiki/php-1.41.0-wmf.24/extensions/DiscussionTools/includes/SpecialTopicSubscriptions.php(43): TablePager->getFullOutput()
#7 /srv/mediawiki/php-1.41.0-wmf.24/includes/specialpage/SpecialPage.php(701): MediaWiki\Extension\DiscussionTools\SpecialTopicSubscriptions->execute(NULL)
#8 /srv/mediawiki/php-1.41.0-wmf.24/includes/specialpage/SpecialPageFactory.php(1566): SpecialPage->run(NULL)
#9 /srv/mediawiki/php-1.41.0-wmf.24/includes/MediaWiki.php(344): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, RequestContext)
#10 /srv/mediawiki/php-1.41.0-wmf.24/includes/MediaWiki.php(942): MediaWiki->performRequest()
#11 /srv/mediawiki/php-1.41.0-wmf.24/includes/MediaWiki.php(591): MediaWiki->main()
#12 /srv/mediawiki/php-1.41.0-wmf.24/index.php(50): MediaWiki->run()
#13 /srv/mediawiki/php-1.41.0-wmf.24/index.php(46): wfIndexMain()
#14 /srv/mediawiki/w/index.php(3): require(string)
#15 {main}
Impact

Few hits on Hebrew Wikipedia, maybe worth investigating.

Notes

Event Timeline

It looks like someone has managed to wind up with a subscription to a topic that Title::makeTitleSafe errors on.

matmarex renamed this task from Wikimedia\Assert\ParameterTypeException: Bad value for parameter $target: must be a LinkTarget|PageReference to Wikimedia\Assert\ParameterTypeException: Bad value for parameter $target: must be a LinkTarget|PageReference when viewing Special:TopicSubscriptions.Sep 5 2023, 11:08 PM

Change 955035 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/DiscussionTools@master] TopicSubscriptionsPager: Handle invalid titles

https://gerrit.wikimedia.org/r/955035

I tested this patch locally by inserting some invalid entries into the database manually. It will display something like this when there's a subscription with an invalid title:

image.png (339×2 px, 85 KB)

I don't know what caused them to appear in production; it might be worth it for someone to find out. Either DiscussionTools is inserting invalid titles in some cases, or the title validity rules changed. For the most part, the invalid titles in subscriptions are harmless, though. Users can still receive notifications for these topics (if they were moved to some valid title), the titles are only used on Special:TopicSubscriptions itself.

I don't know what caused them to appear in production; it might be worth it for someone to find out.

I don't think you can do it through the API, because it explicitly checks Title::newFromText before proceeding (unless there's some sort of encode/decode issue with uncommon title characters, I guess?). However, it looks like SubscribeAction (i.e. the no-JS fallback route) has an onSubmit method that doesn't do any validation...

Change 955035 merged by jenkins-bot:

[mediawiki/extensions/DiscussionTools@master] TopicSubscriptionsPager: Handle invalid titles

https://gerrit.wikimedia.org/r/955035

I have lately been unable to access [[Special:TopicSubscriptions]]. All I see on that special page is an error message (Fatal exception of type "Wikimedia\Assert\ParameterTypeException"). I reported it yesterday on https://w.wiki/7QY6. I do not recall ever using the API to do anything related to topic subscriptions. See screenshot below. Thanks!

Topic Subscriptions Error.png (1×3 px, 245 KB)

I'll backport the fix later today, which will let you access it again, and you'll be able to see which subscription was causing the problem. (It'd be interesting to know for us too.)

I'll backport the fix later today, which will let you access it again, and you'll be able to see which subscription was causing the problem. (It'd be interesting to know for us too.)

Thank you very much! Highly appreciated :)
Note that despite the English interface used at the screenshot I've attached above, the error occurs on the Hebrew Wikipedia (hewiki). I just used an English UI for the screenshot purpose.

Change 955056 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/DiscussionTools@wmf/1.41.0-wmf.24] TopicSubscriptionsPager: Handle invalid titles

https://gerrit.wikimedia.org/r/955056

Change 955058 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/DiscussionTools@wmf/1.41.0-wmf.25] TopicSubscriptionsPager: Handle invalid titles

https://gerrit.wikimedia.org/r/955058

Change 955056 merged by jenkins-bot:

[mediawiki/extensions/DiscussionTools@wmf/1.41.0-wmf.24] TopicSubscriptionsPager: Handle invalid titles

https://gerrit.wikimedia.org/r/955056

Change 955058 merged by jenkins-bot:

[mediawiki/extensions/DiscussionTools@wmf/1.41.0-wmf.25] TopicSubscriptionsPager: Handle invalid titles

https://gerrit.wikimedia.org/r/955058

Mentioned in SAL (#wikimedia-operations) [2023-09-06T20:30:47Z] <taavi@deploy1002> Started scap: Backport for [[gerrit:955054|Article: Check permissions before showing link to view deleted revision (T264765)]], [[gerrit:955055|Article: Check permissions before showing link to view deleted revision (T264765)]], [[gerrit:955056|TopicSubscriptionsPager: Handle invalid titles (T345648)]], [[gerrit:955058|TopicSubscriptionsPager: Handle invalid titles (T345648)]]

Mentioned in SAL (#wikimedia-operations) [2023-09-06T20:32:29Z] <taavi@deploy1002> matmarex and taavi: Backport for [[gerrit:955054|Article: Check permissions before showing link to view deleted revision (T264765)]], [[gerrit:955055|Article: Check permissions before showing link to view deleted revision (T264765)]], [[gerrit:955056|TopicSubscriptionsPager: Handle invalid titles (T345648)]], [[gerrit:955058|TopicSubscriptionsPager: Handle invalid titles (T345648)]] synced to the tes

Mentioned in SAL (#wikimedia-operations) [2023-09-06T20:40:30Z] <taavi@deploy1002> Finished scap: Backport for [[gerrit:955054|Article: Check permissions before showing link to view deleted revision (T264765)]], [[gerrit:955055|Article: Check permissions before showing link to view deleted revision (T264765)]], [[gerrit:955056|TopicSubscriptionsPager: Handle invalid titles (T345648)]], [[gerrit:955058|TopicSubscriptionsPager: Handle invalid titles (T345648)]] (duration: 09m 42s)

@Guycn2 You should be able to access the page now. One (or more) of the rows should display more information about the invalid title. If you don't mind, it would be helpful if you could copy it here. Thanks!

Works like magic! Thanks a lot to anyone involved in fixing this.

The table at [[Special:TopicSubscriptions]] now correctly shows my entire subscription list, consisting of hundreds of discussions, including discussions I've subscribed to _after_ the bug started.

There is generally nothing special or surprising in that table, except for one single row, which seems to be the cause of the now-fixed bug: In this problematic row, the "Topic" column is empty and displays nothing. In fact, I checked this cell at the browser's console, and it does contain a non-breaking space (&nbsp), and that's it (see screenshot). All other cells at the "Topic" column contain, as expected, an anchor tag pointing to the relevant discussion section. They do not contain a &nbsp like the problematic cell does.

I went on to the relevant discussion page to see which section title caused the mess. Apparently, this section name was, when I initially subscribed to this discussion, as follow:

הסתרת תגובות ויצירת הודעות אזהרה רק כלפי עורכים שמתנגדים להסתרת דעותיו ההומופוביות של הרב טאו בדיון שבעמוד השיחה "ספרו החדש של טאו והאשמות לגבי הומופוביה"

However, in a subsequent edit that was made after I had subscribed, the section name was changed to:

הסתרת תגובות בדיון שיחה

This is the edit in which the section name was changed: https://w.wiki/7Qd3

Notice the extra space that was added in that edit right before the closing == sign. Maybe it has something to do with the &nbsp that I've mentioned above? Maybe this bug wouldn't have happened had it not been for this extra space? These are just pure guesses, of course.

Thanks again, and if more information would be helpful to identify the cause of the now-fixed bug, I'd be glad to reply!

Topic subscriptions debugging.png (589×1 px, 308 KB)

Thanks for the details! I think I see the problem – it's because of the length of the original section name (changing it later doesn't make a difference). It requires 282 UTF-8 bytes to represent, but the database field for the section name allows 255 bytes, so when the subscription was added, it was truncated. This wouldn't be a problem by itself – the section name isn't necessary for subscriptions to work, it's only stored to be displayed on Special:TopicSubscriptions – but it just so happens that the 255th byte is a part of a multi-byte character, so truncating it there made it invalid. The page title itself is valid, and it's only invalid when combined with the fragment link pointing to the invalid section name.

We can fix this problem (for future subscriptions) by truncating it in a safe way.

Change 955833 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/DiscussionTools@master] SubscriptionStore: Fix truncating multibyte chars in section names

https://gerrit.wikimedia.org/r/955833

We can fix this problem (for future subscriptions) by truncating it in a safe way.

Could the existing subscriptions also be fixed by dropping the last byte if it’s the first byte of a two-byte character?

They could, but I'm not sure if it's worth the additional effort, as they are already working.

What do you call “working”? The topic title is presumably there because it was considered useful; an empty topic title is definitely not useful.

They're "working" in the sense that Special:TopicSubscriptions loads, and users receive notifications. This was good enough for me. However, I amended my proposed patch now, and it will display the affected topic titles on Special:TopicSubscriptions (truncated to the max available length), instead of an empty cell.

Change 955833 merged by jenkins-bot:

[mediawiki/extensions/DiscussionTools@master] Fix truncating multibyte chars in section names

https://gerrit.wikimedia.org/r/955833

matmarex renamed this task from Wikimedia\Assert\ParameterTypeException: Bad value for parameter $target: must be a LinkTarget|PageReference when viewing Special:TopicSubscriptions to Wikimedia\Assert\ParameterTypeException: Bad value for parameter $target: must be a LinkTarget|PageReference when viewing Special:TopicSubscriptions (caused by section name longer than 255 bytes).Oct 13 2023, 6:32 PM
matmarex moved this task from Code Review to QA on the Editing-team (Kanban Board) board.
matmarex added a project: Editing QA.