Page MenuHomePhabricator

LanguageFallbackChainFactory returns empty fallback chain when it shouldn't
Closed, ResolvedPublic

Description

While working on a hot-fix for T259745: Uncaught ArgumentCountError: Too few arguments to function OOUI\Tag::appendContent(), 0 passed I realized the Wikimedia-production-error probably hints at another bug. This is the code that failed:

$layout->appendContent(
	...$this->getCaptionsContent(
		$entity->getLabels(),
		$this->getLanguagesOrderedByFallbackChain( $entity )
	)
);

Since appendContent() requires at least one argument, it fails when getCaptionsContent() returns an empty array. But wait, how is this possible? getLanguagesOrderedByFallbackChain() is documented to return at least the interface language. So it should be impossible that getCaptionsContent() returns nothing. How can the interface language get lost?

The LanguageFallbackChain in question is created in WikibaseMediaInfoHooks::createEmptyStructuredData() with no $mode flag set, which means it should default to FALLBACK_ALL when LanguageFallbackChainFactory::newFromLanguage() is called. That should always include the original language in the result – but the code path is not obvious.

I guess the task is to find out what's going on here, under which circumstances this LanguageFallbackChain can be empty, or add tracking code for this edge-case and monitor this potential bug further.

Event Timeline

T259744#6364309 mentions the patch that changed the behavior of the factory. It's now possible that language chains can be empty when the interface language is not a valid term language. There are a few language codes that are intentionally excluded from being term languages, e.g. "en-simple".

One possible fix is to make sure all these invalid term languages fall back to a valid one when FALLBACK_SELF (or FALLBACK_ALL) is specified. For example, "en-simple" falls back to "en". At the moment, this exclude-list is hard-coded in WikibaseContentLanguages. Fallbacks are available via core, e.g. the official fallback for "de-formal" is "de".

Thank you for pointing me to this ticket. This ticket should indeed be mostly done when T259783: LanguageFallbackChain does not end in 'en' for language codes that are not a valid format is done. However, getLanguagesOrderedByFallbackChain will semantically change from always at least including the interface language to always including at least the content language. Unfortunately, I missed that during T256405: Investigate where and how \Wikibase\Lib\LanguageFallbackChain is used. And I'm not sure whether that is a problem, because I do not know the domain enough. So, I think this ticket here has its reason to stay open to make sure that is taken care of and not forgotten.

Change 621262 had a related patch set uploaded (by Michael Große; owner: Michael Große):
[mediawiki/extensions/Wikibase@master] Fix Term Fallback chains being empty

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

Change 621262 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Fix Term Fallback chains being empty

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

Addshore claimed this task.