Page MenuHomePhabricator

PreconditionException thrown when viewing Special:GlobalPreferences
Closed, ResolvedPublic3 Estimated Story PointsPRODUCTION ERROR

Description

List of steps to reproduce (step by step, including full links if applicable):

  1. Make Use Legacy Vector preferences globally in GlobalPreferences
  2. Enable local exception for Use Legacy Vector on en.wikipedia.org
  3. Visit https://en.wikipedia.org/wiki/Special:GlobalPreferences?uselang=en

What happens?:
Got [28e20dfe-d195-4c26-af5b-b5c972e050a9] 2021-11-19 09:05:00: Fatal exception of type "Wikimedia\Assert\PreconditionException"

Analyze

Special:GlobalPreferencesunsetunsetenabledenabledenableddisableddisableddisabled
Special:Preferencesenableddisabled(unset) [3]enableddisabled(unset) [3]enableddisabled
globalpreferences.preferences.VectorSkinVersion [1](unset)(unset)"1""1""1""2""2""2"
globalpreferences.localoverrides.VectorSkinVersion [1]"1""2""1""1""2""2""1""2"
options.VectorSkinVersion [2]"1""2""1""1""2""2""1""2"
options.VectorSkinVersion-local-exception [2]"1""1"0"1""1"0"1""1"
resultOKOKOKBrokenBrokenOKBrokenBroken

[1] https://en.wikipedia.org/w/api.php?action=query&meta=globalpreferences
[2] https://en.wikipedia.org/w/api.php?action=query&meta=userinfo&uiprop=options
[3] Disable "Set a local exception for this global preference"

Details

MediaWiki Version
1.38.0-wmf.9
Request URL
https://en.wikipedia.org/wiki/Special:GlobalPreferences

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

It seems to happen when you set Use Legacy Vector to global.

If you check all of the other options except that one Special:GlobalPreferences loads.

A sort of workaround for this would be to go to Special:GlobalPreferences/reset which will remove all your global preferences. You should then be able to load Special:GlobalPreferences.

But having to restore your global preferences afterwards might be a bit inconvenient.

Full stack trace from my local:

[6be6f4f2b495a6fe7cfdcea2] /shareddb/index.php/Special:GlobalPreferences Wikimedia\Assert\PreconditionException: Precondition failed: The "default" param must be a boolean.

Backtrace:

from /home/drw/wikimedia/srv/shareddb/vendor/wikimedia/assert/src/Assert.php(49)
#0 /home/drw/wikimedia/srv/shareddb/skins/Vector/includes/HTMLForm/Fields/HTMLLegacySkinVersionField.php(39): Wikimedia\Assert\Assert::precondition(boolean, string)
#1 /home/drw/wikimedia/srv/shareddb/includes/htmlform/HTMLForm.php(547): Vector\HTMLForm\Fields\HTMLLegacySkinVersionField->__construct(array)
#2 /home/drw/wikimedia/srv/shareddb/includes/htmlform/OOUIHTMLForm.php(52): HTMLForm::loadInputFromParameters(string, array, GlobalPreferences\GlobalPreferencesFormOOUI)
#3 /home/drw/wikimedia/srv/shareddb/includes/htmlform/HTMLForm.php(396): OOUIHTMLForm::loadInputFromParameters(string, array, GlobalPreferences\GlobalPreferencesFormOOUI)
#4 /home/drw/wikimedia/srv/shareddb/includes/htmlform/HTMLForm.php(373): HTMLForm->addFields(array)
#5 /home/drw/wikimedia/srv/shareddb/includes/htmlform/OOUIHTMLForm.php(38): HTMLForm->__construct(array, RequestContext, string)
#6 /home/drw/wikimedia/srv/shareddb/includes/preferences/DefaultPreferencesFactory.php(1691): OOUIHTMLForm->__construct(array, RequestContext, string)
#7 /home/drw/wikimedia/srv/shareddb/extensions/GlobalPreferences/includes/SpecialGlobalPreferences.php(76): MediaWiki\Preferences\DefaultPreferencesFactory->getForm(User, RequestContext, string)
#8 /home/drw/wikimedia/srv/shareddb/includes/specials/SpecialPreferences.php(110): GlobalPreferences\SpecialGlobalPreferences->getFormObject(User, RequestContext)
#9 /home/drw/wikimedia/srv/shareddb/extensions/GlobalPreferences/includes/SpecialGlobalPreferences.php(31): SpecialPreferences->execute(NULL)
#10 /home/drw/wikimedia/srv/shareddb/includes/specialpage/SpecialPage.php(647): GlobalPreferences\SpecialGlobalPreferences->execute(NULL)
#11 /home/drw/wikimedia/srv/shareddb/includes/specialpage/SpecialPageFactory.php(1374): SpecialPage->run(NULL)
#12 /home/drw/wikimedia/srv/shareddb/includes/MediaWiki.php(314): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, RequestContext)
#13 /home/drw/wikimedia/srv/shareddb/includes/MediaWiki.php(925): MediaWiki->performRequest()
#14 /home/drw/wikimedia/srv/shareddb/includes/MediaWiki.php(559): MediaWiki->main()
#15 /home/drw/wikimedia/srv/shareddb/index.php(53): MediaWiki->run()
#16 /home/drw/wikimedia/srv/shareddb/index.php(46): wfIndexMain()
#17 {main}

A sort of workaround for this would be to go to Special:GlobalPreferences/reset which will remove all your global preferences. You should then be able to load Special:GlobalPreferences.

I can disable it on other wikis.

For some reason, I cannot reproduce this bug anymore either on beta or production (enwiki).

For some reason, I cannot reproduce this bug anymore either on beta or production (enwiki).

You need to set local overrides. Try the following script.

var api = new mw.Api()
api.postWithEditToken({action:'globalpreferences', optionname:'VectorSkinVersion', optionvalue: '2'})
api.postWithEditToken({action:'globalpreferenceoverrides', optionname:'VectorSkinVersion', optionvalue: '2'})

GlobalPreferencesFactory.php#L256 is the offending line. If commented out, Special:GlobalPreferences loads as expected, however global preferences may not be displayed correctly, which is part of what r737698 was meant to fix.

The other obvious fix is to remove the assertion in Vector's HTMLLegacySkinVersionField.php. This seems to work without any obvious repercussions... I'm able to (un)set a local exception and the correct value is displayed at both Special:Preferences and Special:GlobalPreferences. The commit message for r619475 goes into a little detail and notes the discrepancy between where we expect a boolean versus a string value, but I haven't wrapped my head around why this is or why the assertion is needed. Pinging @phuedx in case they have any insight (I know you wrote the patch > 1 year ago)? Do you think it's safe to remove the assertion?

If we wanted a "quick fix" I am leaning towards removing the assertion, but again I'm probably missing something. Also pinging @Func and @Samwilson in case you have input.

MusikAnimal changed the subtype of this task from "Bug Report" to "Production Error".
MusikAnimal set Request URL to https://en.wikipedia.org/wiki/Special:GlobalPreferences.Nov 22 2021, 9:01 PM
MusikAnimal set Release Version to 1.38.0-wmf.9.
MusikAnimal set Phatality ID to dee9c6180ce3b43f21b82f15f6d509e9fa8c5304e19c081db328c461b00502e4.

I agree, on the face of it, it seems the simplest fix is to remove the assertion. But I'm confused: the default has to be a boolean (because it's wrapping HTMLCheckField), but the actual value of the user option is '1' or '2'? I guess I don't quite understand why it's not just a normal boolean checkbox, but there's obviously a reason!

If you're happy removing the assertion, and no one says otherwise, then I say go for it.

Change 740713 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/skins/Vector@master] HTMLLegacySkinVersionField: accept string 'default' value

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

The other obvious fix is to remove the assertion in Vector's HTMLLegacySkinVersionField.php. This seems to work without any obvious repercussions... I'm able to (un)set a local exception and the correct value is displayed at both Special:Preferences and Special:GlobalPreferences. The commit message for r619475 goes into a little detail and notes the discrepancy between where we expect a boolean versus a string value, but I haven't wrapped my head around why this is or why the assertion is needed. Pinging @phuedx in case they have any insight (I know you wrote the patch > 1 year ago)? Do you think it's safe to remove the assertion?

With your update to GlobalPreferences, I think it's safe to remove the assertion. Indeed, I think it's possible to remove the custom field as well but that's out of scope for this task IMO.

… Also, as I said on the patch: TYVM for the investigation and patch!

Change 740713 merged by jenkins-bot:

[mediawiki/skins/Vector@master] HTMLLegacySkinVersionField: accept string 'default' value

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

With your update to GlobalPreferences, I think it's safe to remove the assertion. Indeed, I think it's possible to remove the custom field as well but that's out of scope for this task IMO.

I had a feeling that was the case, but yeah to keep the risks minimal I was hesitant to make any further assumptions. Thanks for the code review!

MusikAnimal set the point value for this task to 3.Nov 29 2021, 6:50 PM
dom_walden moved this task from QA 🐛 to Done 🏁 on the Community-Tech (CommTech-Sprint-14) board.

After setting local overrides for as many user preferences as I can find, I am still able to load the Special:GlobalPreferences form, with no errors.

Because the set of user preferences is different per wiki, I tried a number of different beta wikis (German Wikipedia, German Wiktionary, Spanish Wikibooks, English Wikinews, Wikiquote, Wikisource, Wikiversity, Wikivoyage, Commons and Wikidata). I set all there user options globally, and then set all the local overrides, then reloaded the Special:GlobalPreferences page.

Nothing to see here, so moving straight to Done.

Test environment: Various beta wikis (mentioned above) MediaWiki 1.38.0-alpha (cb912e4) 12:52, 30 November 2021. GlobalPreferences 0.1.2 (a946ed7) 00:07, 30 November 2021.