Page MenuHomePhabricator

Key "CanonicalNamespaceNames" not found in input sources in includes/config/ServiceOptions.php:52
Open, HighPublic

Description

Hi, testing out REL1_34, i'm getting:

[31-Oct-2019 15:08:23 UTC] PHP Fatal error:  Uncaught InvalidArgumentException: Key "CanonicalNamespaceNames" not found in input sources in /srv/mediawiki/w/includes/config/ServiceOptions.php:52
Stack trace:
#0 /srv/mediawiki/w/includes/ServiceWiring.php(519): MediaWiki\Config\ServiceOptions->__construct(Array, Object(GlobalVarConfig))
#1 /srv/mediawiki/w/includes/libs/services/ServiceContainer.php(458): Wikimedia\Services\ServiceContainer->{closure}(Object(MediaWiki\MediaWikiServices))
#2 /srv/mediawiki/w/includes/libs/services/ServiceContainer.php(427): Wikimedia\Services\ServiceContainer->createService('NamespaceInfo')
#3 /srv/mediawiki/w/includes/MediaWikiServices.php(770): Wikimedia\Services\ServiceContainer->getService('NamespaceInfo')
#4 /srv/mediawiki/w/includes/MWNamespace.php(238): MediaWiki\MediaWikiServices->getNamespaceInfo()
#5 /srv/mediawiki/w/extensions/ArticleRatings/ArticleRatingsHooks.php(10): MWNamespace::getContentNamespaces()
#6 /srv/mediawiki/w/includes/registration/ExtensionRegistry.php(440): AreHooks::onRegisterExtension(Array)
 in /srv/mediawiki/w/includes/config/ServiceOptions.php on line 52

Seems that ArticleRatings calls MWNamespace::getContentNamespaces().

php version: 7.3

Event Timeline

Paladox created this task.Oct 31 2019, 3:23 PM
Paladox updated the task description. (Show Details)
Reedy renamed this task from Key "CanonicalNamespaceNames" not found in input sources in /srv/mediawiki/w/includes/config/ServiceOptions.php:52 to Key "CanonicalNamespaceNames" not found in input sources in includes/config/ServiceOptions.php:52.Oct 31 2019, 3:33 PM
Reedy added a project: MW-1.34-release.
Reedy added a comment.Oct 31 2019, 3:41 PM

Don't suppose you know if this works on master?

Paladox added a comment.EditedOct 31 2019, 3:55 PM

Nope :(

I found doing https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/ArticleRatings/+/547564/ fixed the issue.

Tests fail with that change :(

Reedy added a comment.Oct 31 2019, 3:57 PM

From master...

	'NamespaceInfo' => function ( MediaWikiServices $services ) : NamespaceInfo {
		return new NamespaceInfo( new ServiceOptions( NamespaceInfo::CONSTRUCTOR_OPTIONS,
			$services->getMainConfig() ) );
	},

So it's seemingly not passing in CanonicalNamespaceNames/wgCanonicalNamespaceNames?

Paladox added a comment.EditedOct 31 2019, 4:01 PM

Fails on the master branch too https://integration.wikimedia.org/ci/job/quibble-vendor-mysql-php72-docker/27780/console

16:00:27 Fatal error: Uncaught InvalidArgumentException: Key "CanonicalNamespaceNames" not found in input sources in /workspace/src/includes/config/ServiceOptions.php:52
16:00:27 Stack trace:
16:00:27 #0 /workspace/src/includes/ServiceWiring.php(580): MediaWiki\Config\ServiceOptions->__construct(Array, Object(GlobalVarConfig))
16:00:27 #1 /workspace/src/includes/libs/services/ServiceContainer.php(458): Wikimedia\Services\ServiceContainer->{closure}(Object(MediaWiki\MediaWikiServices))
16:00:27 #2 /workspace/src/includes/libs/services/ServiceContainer.php(427): Wikimedia\Services\ServiceContainer->createService('NamespaceInfo')
16:00:27 #3 /workspace/src/includes/MediaWikiServices.php(817): Wikimedia\Services\ServiceContainer->getService('NamespaceInfo')
16:00:27 #4 /workspace/src/includes/MWNamespace.php(238): MediaWiki\MediaWikiServices->getNamespaceInfo()
16:00:27 #5 /workspace/src/extensions/ArticleRatings/ArticleRatingsHooks.php(10): MWNamespace::getContentNamespaces()
16:00:27 #6 /workspace/src/includes/registration/ExtensionRegistry.php(436): AreHooks::onRegisterExtension(Array)
16:00:27 #7 /workspace/sr in /workspace/src/includes/config/ServiceOptions.php on line 52
16:00:27 PHP Fatal error:  Uncaught InvalidArgumentException: Key "CanonicalNamespaceNames" not found in input sources in /workspace/src/includes/config/ServiceOptions.php:52
16:00:27 Stack trace:
16:00:27 #0 /workspace/src/includes/ServiceWiring.php(580): MediaWiki\Config\ServiceOptions->__construct(Array, Object(GlobalVarConfig))
16:00:27 #1 /workspace/src/includes/libs/services/ServiceContainer.php(458): Wikimedia\Services\ServiceContainer->{closure}(Object(MediaWiki\MediaWikiServices))
16:00:27 #2 /workspace/src/includes/libs/services/ServiceContainer.php(427): Wikimedia\Services\ServiceContainer->createService('NamespaceInfo')
16:00:27 #3 /workspace/src/includes/MediaWikiServices.php(817): Wikimedia\Services\ServiceContainer->getService('NamespaceInfo')
16:00:27 #4 /workspace/src/includes/MWNamespace.php(238): MediaWiki\MediaWikiServices->getNamespaceInfo()
16:00:27 #5 /workspace/src/extensions/ArticleRatings/ArticleRatingsHooks.php(10): MWNamespace::getContentNamespaces()
16:00:27 #6 /workspace/src/includes/registration/ExtensionRegistry.php(436): AreHooks::onRegisterExtension(Array)
16:00:27 #7 /workspace/sr in /workspace/src/includes/config/ServiceOptions.php on line 52
Reedy added a comment.Oct 31 2019, 4:04 PM

I wonder whether the problem is the extension is calling this too early. I've no idea if it should work

	"callback": "AreHooks::onRegisterExtension",
	/**
	 * Extension registration callback -- set $wgARENamespaces to $wgContentNa
	 */
	public static function onRegisterExtension() {
		global $wgARENamespaces;
		$wgARENamespaces = MWNamespace::getContentNamespaces();
	}

It definitely works fine after MW is setup (ie via eval.php)

reedy@mwdebug1002:~$ mwscript eval.php enwiki
> var_dump( MWNamespace::getContentNamespaces() );
array(1) {
  [0]=>
  int(0)
}

Just swap it to use ExtensionFunctions instead in extension.json?

Change 547564 had a related patch set uploaded (by Paladox; owner: Paladox):
[mediawiki/extensions/ArticleRatings@master] Convert callback to use ExtensionFunctions

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

Reedy moved this task from Backlog to Bugs on the ArticleRatings board.Nov 1 2019, 10:43 AM
Krinkle triaged this task as High priority.Nov 6 2019, 12:38 AM
Krinkle added a subscriber: Krinkle.

This extension isn't bundled with core, and the issue seems to be within the extension, with the pending fix being local to the extension, as such does not need to delay release from what I can see.

Krinkle renamed this task from Key "CanonicalNamespaceNames" not found in input sources in includes/config/ServiceOptions.php:52 to ArticleRatingsHooks.php: Key "CanonicalNamespaceNames" not found in input sources in includes/config/ServiceOptions.php:52.Nov 6 2019, 7:59 PM
Krinkle renamed this task from ArticleRatingsHooks.php: Key "CanonicalNamespaceNames" not found in input sources in includes/config/ServiceOptions.php:52 to Key "CanonicalNamespaceNames" not found in input sources in includes/config/ServiceOptions.php:52.Nov 6 2019, 8:02 PM
Krinkle added a project: MW-1.34-release.
Krinkle added a comment.EditedNov 6 2019, 8:06 PM

The extension code is encountering this fatal exception when calling core's code MWNamespace::getContentNamespaces from a modern extension registry callback.

Uncaught InvalidArgumentException: Key "CanonicalNamespaceNames" not found in input sources in /srv/mediawiki/w/includes/config/ServiceOptions.php:52

This is because wgCanonicalNamespaceNames is defined in Setup.php (instead of DefaultSettings.php), after the point in Setup.php where ExtensionRegistry::getInstance()->loadFromQueue() is called. As such, this critical key is undefined.

It is fair to assume configuration to not have finalised by the time extension registry is called, because processing extension registry callbacks and executing Setup.php is part of "finalising site configuration variables".

EDIT: In this case, it is indeed something site admins and extension authors need to be concerned with given that wgCanonicalNamespaceNames is extended with wgExtraNamespaces. This singleton cannot be safely instantiated by the time extension registry callbacks are processed.

It worked before 1.34 but only because the ServiceWiring did not strictly enforce existence of the variable (thus falling back to null thanks to PHP lazily creating a variable when stating global $wgFoo, without even an error Notice). This would have caused bugs due to the un-extended state being cached. This is working as expected and cannot be supported safely during extension registry.

The logic that the ArticleRatings is using here is likely also not possible because moving it to a post-setup extension function means that the configuration won't inform services, and can't be overridden by LocalSettings, thus making it not useful as a global variable.

Krinkle removed a subscriber: Krinkle.

Change 560347 had a related patch set uploaded (by Paladox; owner: Paladox):
[mediawiki/extensions/ArticleRatings@REL1_34] Convert extension registry callback back to old-style ExtensionFunctions

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

Hello, can you tell me status of these patches. because https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ArticleRatings/+/552375 fails and error is same?