Page MenuHomePhabricator

[CLIENT] PHP Notice: Undefined offset: 1 and 2 in Wikibase ApiListEntityUsage (wblistentityusage) and ApiPropsEntityUsage (wbentityusage)
Closed, ResolvedPublicPRODUCTION ERROR

Description

These two classes do something like:

[ $pageContinue, $entityContinue, $aspectContinue ] = explode( '|', $continueParam, 3 );

which produces a PHP warning if the continue parameter isn’t in the expected format. Reasonably harmless, but we should still fix it.

wblistentityusage request URL and Logstash:

PHP Notice: Undefined offset: 1
from /srv/mediawiki/php-1.40.0-wmf.8/extensions/Wikibase/client/includes/Api/ApiListEntityUsage.php(198)
#0 /srv/mediawiki/php-1.40.0-wmf.8/extensions/Wikibase/client/includes/Api/ApiListEntityUsage.php(198): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.40.0-wmf.8/extensions/Wikibase/client/includes/Api/ApiListEntityUsage.php(180): Wikibase\Client\Api\ApiListEntityUsage->addContinue(string)
#2 /srv/mediawiki/php-1.40.0-wmf.8/extensions/Wikibase/client/includes/Api/ApiListEntityUsage.php(53): Wikibase\Client\Api\ApiListEntityUsage->doQuery(array, NULL)
#3 /srv/mediawiki/php-1.40.0-wmf.8/extensions/Wikibase/client/includes/Api/ApiListEntityUsage.php(48): Wikibase\Client\Api\ApiListEntityUsage->run()
#4 /srv/mediawiki/php-1.40.0-wmf.8/includes/api/ApiQuery.php(671): Wikibase\Client\Api\ApiListEntityUsage->execute()
#5 /srv/mediawiki/php-1.40.0-wmf.8/includes/api/ApiMain.php(1903): ApiQuery->execute()
#6 /srv/mediawiki/php-1.40.0-wmf.8/includes/api/ApiMain.php(878): ApiMain->executeAction()
#7 /srv/mediawiki/php-1.40.0-wmf.8/includes/api/ApiMain.php(849): ApiMain->executeActionWithErrorHandling()
#8 /srv/mediawiki/php-1.40.0-wmf.8/api.php(90): ApiMain->execute()
#9 /srv/mediawiki/php-1.40.0-wmf.8/api.php(45): wfApiMain()
#10 /srv/mediawiki/w/api.php(3): require(string)
#11 {main}

wbpropsentityusage request URL and Logstash:

PHP Notice: Undefined offset: 1
from /srv/mediawiki/php-1.40.0-wmf.8/extensions/Wikibase/client/includes/Api/ApiPropsEntityUsage.php(129)
#0 /srv/mediawiki/php-1.40.0-wmf.8/extensions/Wikibase/client/includes/Api/ApiPropsEntityUsage.php(129): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.40.0-wmf.8/extensions/Wikibase/client/includes/Api/ApiPropsEntityUsage.php(38): Wikibase\Client\Api\ApiPropsEntityUsage->doQuery(array)
#2 /srv/mediawiki/php-1.40.0-wmf.8/includes/api/ApiQuery.php(671): Wikibase\Client\Api\ApiPropsEntityUsage->execute()
#3 /srv/mediawiki/php-1.40.0-wmf.8/includes/api/ApiMain.php(1903): ApiQuery->execute()
#4 /srv/mediawiki/php-1.40.0-wmf.8/includes/api/ApiMain.php(878): ApiMain->executeAction()
#5 /srv/mediawiki/php-1.40.0-wmf.8/includes/api/ApiMain.php(849): ApiMain->executeActionWithErrorHandling()
#6 /srv/mediawiki/php-1.40.0-wmf.8/api.php(90): ApiMain->execute()
#7 /srv/mediawiki/php-1.40.0-wmf.8/api.php(45): wfApiMain()
#8 /srv/mediawiki/w/api.php(3): require(string)
#9 {main}

Steps to reproduce:

  • have error_reporting( E_ALL ); and ini_set( 'display_errors', 1 ); in your LocalSettings.php
  • visit one of these URLs on your local wiki:
    • api.php?action=query&list=wblistentityusage&wbleuentities=Q1&wbleucontinue=-
    • api.php?action=query&prop=wbentityusage&titles=Q1&wbeucontinue=- (you might need to change Q1 to Item:Q1 or another title – needs to be the title for an existing item’s page)
  • (the lack of &format=json is important – the warnings are only visible if the HTML representation is shown)

Acceptance criteria:

  • neither of the two URLs listed above produces a warning anymore

Note: ListSubscribers does it like this instead:

$continueParams = explode( '|', $continueParam );
if ( count( $continueParams ) !== 2 ) {
	$this->errorReporter->dieError(
		'Unable to parse continue param',
		'param-invalid'
	);
}
$entityContinueSql = $db->addQuotes( $continueParams[0] );
$wikiContinueSql = $db->addQuotes( $continueParams[1] );

Event Timeline

ListSubscribers does it like this instead:

$continueParams = explode( '|', $continueParam );
if ( count( $continueParams ) !== 2 ) {
	$this->errorReporter->dieError(
		'Unable to parse continue param',
		'param-invalid'
	);
}
$entityContinueSql = $db->addQuotes( $continueParams[0] );
$wikiContinueSql = $db->addQuotes( $continueParams[1] );

(In Use database buildComparison() method, for T321422, I’ve proposed inlining those last two variables.)

Still happening from time to time (just randomly saw it again in logspam-watch output).

ItamarWMDE renamed this task from PHP Notice: Undefined offset: 1 and 2 in Wikibase ApiListEntityUsage (wblistentityusage) and ApiPropsEntityUsage (wbentityusage) to [CLIENT] PHP Notice: Undefined offset: 1 and 2 in Wikibase ApiListEntityUsage (wblistentityusage) and ApiPropsEntityUsage (wbentityusage).Nov 8 2023, 10:51 AM
ItamarWMDE moved this task from Incoming to [DOT] By Project on the wmde-wikidata-tech board.

Prio Notes:

Impact AreaAffected
production / end userscould affect
monitoringno
development effortsno
onboarding effortsno
additional stakeholdersyes (logspam)
ItamarWMDE renamed this task from [CLIENT] PHP Notice: Undefined offset: 1 and 2 in Wikibase ApiListEntityUsage (wblistentityusage) and ApiPropsEntityUsage (wbentityusage) to [CLIENT] [SW] PHP Notice: Undefined offset: 1 and 2 in Wikibase ApiListEntityUsage (wblistentityusage) and ApiPropsEntityUsage (wbentityusage).Jan 16 2024, 4:43 PM
ArthurTaylor renamed this task from [CLIENT] [SW] PHP Notice: Undefined offset: 1 and 2 in Wikibase ApiListEntityUsage (wblistentityusage) and ApiPropsEntityUsage (wbentityusage) to [CLIENT] PHP Notice: Undefined offset: 1 and 2 in Wikibase ApiListEntityUsage (wblistentityusage) and ApiPropsEntityUsage (wbentityusage).Feb 28 2024, 10:22 AM
ArthurTaylor updated the task description. (Show Details)
Restricted Application changed the subtype of this task from "Task" to "Production Error". · View Herald TranscriptDec 4 2024, 10:55 AM

@ItamarWMDE @Lucas_Werkmeister_WMDE - Although I find the requirements of the ticket clear and actionable, it doesn't quite meet our definition of ready. Please add Acceptance Criteria, and make the steps to reproduce more explicit (the URLs are helpful, but they could be more explicit).

Is it better now? (It turns out one of the URLs had become invalid in the meantime due to T196962.)

Change #1101846 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/Wikibase@master] Add error handling for `continue` parameter to entityusage API

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

Change #1101846 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Add error handling for `continue` parameter to entityusage API

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

Hm, I think we forgot to define an interface message here:

warnings":{"wblistentityusage":{"warnings":"⧼apiwarn-ignoring-invalid-continue-parameter⧽"}}

(And/or meant to refer to an existing MediaWiki core message but used the wrong key?)

Change #1109688 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] client: Turn invalid continue warning into error

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

Change #1109688 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] client: Turn invalid continue warning into error

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

Lucas_Werkmeister_WMDE assigned this task to ArthurTaylor.

Hm, I think we forgot to define an interface message here:

warnings":{"wblistentityusage":{"warnings":"⧼apiwarn-ignoring-invalid-continue-parameter⧽"}}

Fixed on Beta (wblistentityusage URL, wbentityusage URL) with the above change; I think that’s good enough to close the task without waiting for next week’s train.

(Also, the warnings in logstash went away, which is the most important thing but I forgot to verify the other day.)