Page MenuHomePhabricator

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

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 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.

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

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?

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

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

Krinkle triaged this task as High priority.Nov 6 2019, 12:38 AM
Krinkle subscribed.

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.

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.

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

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

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

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?

(bump)

Change 560347 abandoned by Umherirrender:
[mediawiki/extensions/ArticleRatings@REL1_34] Convert extension registry callback back to old-style ExtensionFunctions

Reason:
release is end of life

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

Change 689204 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/extensions/ArticleRatings@master] When $wgARENamespaces is empty use content namespaces

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

Change 689204 merged by jenkins-bot:

[mediawiki/extensions/ArticleRatings@master] When $wgARENamespaces is empty use content namespaces

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

Kizule assigned this task to Umherirrender.
Kizule added a subscriber: Umherirrender.

Fixed in master branch, yay! \o/

Thanks @Umherirrender

Change 690074 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/extensions/ArticleRatings@REL1_36] When $wgARENamespaces is empty use content namespaces

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

Change 690075 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/extensions/ArticleRatings@REL1_35] When $wgARENamespaces is empty use content namespaces

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

Change 547564 abandoned by Umherirrender:

[mediawiki/extensions/ArticleRatings@master] Remove callback

Reason:

Superseeded by Ie8fb45381901f7299ee270841048484501c3f3ea

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

Change 634001 abandoned by Umherirrender:

[mediawiki/extensions/ArticleRatings@REL1_35] Convert extension registry callback back to old-style ExtensionFunctions

Reason:

Superseeded by Ie8fb45381901f7299ee270841048484501c3f3ea

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

Change 690074 merged by jenkins-bot:

[mediawiki/extensions/ArticleRatings@REL1_36] When $wgARENamespaces is empty use content namespaces

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

Change 690075 merged by jenkins-bot:

[mediawiki/extensions/ArticleRatings@REL1_35] When $wgARENamespaces is empty use content namespaces

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