Page MenuHomePhabricator

Argument 1 passed to Parser::fetchTemplateAndTitle() must be an instance of Title, null given, called in /srv/mediawiki/php-1.35.0-wmf.30/extensions/Quiz/includes/Quiz.php on line 258
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error

MediaWiki version: 1.35.0-wmf.30

message
Argument 1 passed to Parser::fetchTemplateAndTitle() must be an instance of Title, null given, called in /srv/mediawiki/php-1.35.0-wmf.30/extensions/Quiz/includes/Quiz.php on line 258

Impact

Started happening after promoting train to group1, but not initially enough to raise deployer concerns that it warranted blocking train. Conversation in the weekly Train Log Triage session led to the conclusion that it would likely break all quizzes once they fall out of cache, so now treating as a blocker.

Details

Request ID
Xql8xwpAMNAAAsAnCN0AAAAE
Request URL
https://it.wikiversity.org/wiki/Apparato_respiratorio_(scuola_media)
Stack Trace
exception.trace
#0 /srv/mediawiki/php-1.35.0-wmf.30/extensions/Quiz/includes/Quiz.php(258): Parser->fetchTemplateAndTitle(NULL)
#1 [internal function]: Quiz->parseInclude(array)
#2 /srv/mediawiki/php-1.35.0-wmf.30/extensions/Quiz/includes/Quiz.php(245): preg_replace_callback(string, array, string)
#3 /srv/mediawiki/php-1.35.0-wmf.30/extensions/Quiz/includes/Quiz.php(205): Quiz->parseIncludes(string)
#4 /srv/mediawiki/php-1.35.0-wmf.30/extensions/Quiz/includes/QuizHooks.php(28): Quiz->parseQuiz(string)
#5 /srv/mediawiki/php-1.35.0-wmf.30/includes/parser/Parser.php(3858): QuizHooks::renderQuiz(string, array, Parser, PPFrame_Hash)
#6 /srv/mediawiki/php-1.35.0-wmf.30/includes/parser/PPFrame_Hash.php(327): Parser->extensionSubstitution(array, PPFrame_Hash)
#7 /srv/mediawiki/php-1.35.0-wmf.30/includes/parser/Parser.php(2866): PPFrame_Hash->expand(PPNode_Hash_Tree, integer)
#8 /srv/mediawiki/php-1.35.0-wmf.30/includes/parser/Parser.php(1552): Parser->replaceVariables(string)
#9 /srv/mediawiki/php-1.35.0-wmf.30/includes/parser/Parser.php(639): Parser->internalParse(string)
#10 /srv/mediawiki/php-1.35.0-wmf.30/includes/content/WikitextContent.php(368): Parser->parse(string, Title, ParserOptions, boolean, boolean, integer)
#11 /srv/mediawiki/php-1.35.0-wmf.30/includes/content/AbstractContent.php(565): WikitextContent->fillParserOutput(Title, integer, ParserOptions, boolean, ParserOutput)
#12 /srv/mediawiki/php-1.35.0-wmf.30/includes/Revision/RenderedRevision.php(267): AbstractContent->getParserOutput(Title, integer, ParserOptions, boolean)
#13 /srv/mediawiki/php-1.35.0-wmf.30/includes/Revision/RenderedRevision.php(236): MediaWiki\Revision\RenderedRevision->getSlotParserOutputUncached(WikitextContent, boolean)
#14 /srv/mediawiki/php-1.35.0-wmf.30/includes/Revision/RevisionRenderer.php(215): MediaWiki\Revision\RenderedRevision->getSlotParserOutput(string)
#15 /srv/mediawiki/php-1.35.0-wmf.30/includes/Revision/RevisionRenderer.php(152): MediaWiki\Revision\RevisionRenderer->combineSlotOutput(MediaWiki\Revision\RenderedRevision, array)
#16 [internal function]: MediaWiki\Revision\RevisionRenderer->MediaWiki\Revision\{closure}(MediaWiki\Revision\RenderedRevision, array)
#17 /srv/mediawiki/php-1.35.0-wmf.30/includes/Revision/RenderedRevision.php(198): call_user_func(Closure, MediaWiki\Revision\RenderedRevision, array)
#18 /srv/mediawiki/php-1.35.0-wmf.30/includes/poolcounter/PoolWorkArticleView.php(204): MediaWiki\Revision\RenderedRevision->getRevisionParserOutput()
#19 /srv/mediawiki/php-1.35.0-wmf.30/includes/poolcounter/PoolCounterWork.php(128): PoolWorkArticleView->doWork()
#20 /srv/mediawiki/php-1.35.0-wmf.30/includes/page/Article.php(796): PoolCounterWork->execute()
#21 /srv/mediawiki/php-1.35.0-wmf.30/includes/actions/ViewAction.php(66): Article->view()
#22 /srv/mediawiki/php-1.35.0-wmf.30/includes/MediaWiki.php(519): ViewAction->show()
#23 /srv/mediawiki/php-1.35.0-wmf.30/includes/MediaWiki.php(305): MediaWiki->performAction(Article, Title)
#24 /srv/mediawiki/php-1.35.0-wmf.30/includes/MediaWiki.php(973): MediaWiki->performRequest()
#25 /srv/mediawiki/php-1.35.0-wmf.30/includes/MediaWiki.php(535): MediaWiki->main()
#26 /srv/mediawiki/php-1.35.0-wmf.30/index.php(47): MediaWiki->run()
#27 /srv/mediawiki/w/index.php(3): require(string)
#28 {main}

Event Timeline

brennen added subscribers: cscott, brennen.

I notice 07cccb66 touches fetchTemplateAndTitle() - @cscott, any thoughts on this one?

diff --git a/includes/Quiz.php b/includes/Quiz.php
index 0866bf9..61c1765 100644
--- a/includes/Quiz.php
+++ b/includes/Quiz.php
@@ -255,7 +255,7 @@ class Quiz {
         */
        private function parseInclude( $matches ) {
                $title = Title::makeTitleSafe( NS_MAIN, $matches[1] );
-               $text = $this->mParser->fetchTemplate( $title );
+               $text = $this->mParser->fetchTemplateAndTitle( $title )[0];
                $output = '';
                if ( preg_match( '`<quiz[^>]*>(.*?)</quiz>`sU', $text, $unparsedQuiz ) ) {
                        // Remove inclusions from included quiz.
LarsWirzenius triaged this task as Unbreak Now! priority.Apr 29 2020, 6:05 PM

This is a train blocker now.

Per conversation in Train Log Triage meeting, marking blocker and tentatively assigning to cscott.

I notice 07cccb66 touches fetchTemplateAndTitle() - @cscott, any thoughts on this one?

This patch was merged Jan 29 ( https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Quiz/+/568158 ) though and presumably deployed in Feb? So, my guess is something else changed that is triggering this. I'll peek at the Parser briefly, but I imagine @cscott might be able to tell what is going on here better.

I don't think 25f3b8ad68acbc2ce18b1c836e0355178d5afc82 / 07cccb6666eafe39efb629c051cfb3669b8f072d is actually responsible, since the definition of Parser::fetchTemplate() in core is:

	public function fetchTemplate( Title $title ) {
		wfDeprecated( __METHOD__, '1.35' );
		return $this->fetchTemplateAndTitle( $title )[0];
	}

aka, doing the exact same thing. But probably whatever patch added the Title type declaration to fetchTemplate (and probably to fetchTemplateAndTitle at the same time) is the actual culprit. I guess maybe Quiz had a template callback registered that replaced the null Title with a 'real' one? I'll keep this one assigned to me and get a patch working regardless...

https://github.com/wikimedia/mediawiki/blob/master/includes/parser/Parser.php#L3531-L3534 indicates the change to Quiz is legitimate ... the proxying from fetchTemplate -> fetchTemplateAndTitle in Parser.php just got inlined into the Quiz extension.

The actual culprit appears to be 99104944e884754fd39a3aabc55f721dbe322d54 by @Fomafix, but I C+2'ed it so I'm still on the hook. It was included first in 1.35.0-wmf.30.

This is the relevant code in Quiz:

	private function parseInclude( $matches ) {
		$title = Title::makeTitleSafe( NS_MAIN, $matches[1] );
		$text = $this->mParser->fetchTemplateAndTitle( $title )[0];
		$output = '';

The only time Title::makeTitleSafe returns null is if there's an error, like an invalid namespace or malformed Title. So this is only likely to be an issue on a page where the quiz is already broken, that is, has a bad inclusion. On the request URL mentioned above, the issue is {{ip|wikt}}, and ip|wikt is not a valid title.

That's just to inform the severity discussions. I don't think this will "break all quizes" as they fall out of cache. (But a patch won't be hard anyway and I'll have one in a few minutes, so the severity discussion is probably moot.)

Change 593318 had a related patch set uploaded (by C. Scott Ananian; owner: C. Scott Ananian):
[mediawiki/extensions/Quiz@master] Don't crash if quiz attempts to include a bad title

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

Change 593318 merged by jenkins-bot:
[mediawiki/extensions/Quiz@master] Don't crash if quiz attempts to include a bad title

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

Change 593319 had a related patch set uploaded (by Jforrester; owner: C. Scott Ananian):
[mediawiki/extensions/Quiz@wmf/1.35.0-wmf.30] Don't crash if quiz attempts to include a bad title

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

Change 593319 merged by jenkins-bot:
[mediawiki/extensions/Quiz@wmf/1.35.0-wmf.30] Don't crash if quiz attempts to include a bad title

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

Mentioned in SAL (#wikimedia-operations) [2020-04-29T21:17:01Z] <jforrester@deploy1001> Synchronized php-1.35.0-wmf.30/extensions/Quiz/includes/Quiz.php: Don't crash if quiz attempts to include a bad title T251409 (duration: 01m 06s)

Jdforrester-WMF subscribed.

Deployed and confirmed.

The only time Title::makeTitleSafe returns null is if there's an error, like an invalid namespace or malformed Title. So this is only likely to be an issue on a page where the quiz is already broken, that is, has a bad inclusion. On the request URL mentioned above, the issue is {{ip|wikt}}, and ip|wikt is not a valid title.

Makes sense - so probably wouldn't have been too substantial an impact after all. Thanks much for the quick turnaround, nonetheless.