Page MenuHomePhabricator

ContentTranslation API emits PHP error "Cannot access property on non-object" from some queries
Closed, DuplicatePublicPRODUCTION ERROR

Description

Error

Request ID: W6KzfQrAEHYAAKeI6lkAAABW

message
[{exception_id}] {exception_url}   ErrorException from line 52 of /srv/mediawiki/php-1.32.0-wmf.22/extensions/ContentTranslation/api/ApiQueryContentTranslation.php: PHP Notice: Cannot access property on non-object
stacktrace
#0 /srv/mediawiki/php-1.32.0-wmf.22/extensions/ContentTranslation/api/ApiQueryContentTranslation.php(52): MWExceptionHandler::handleError(integer, string, string, integer, array, array)
#1 /srv/mediawiki/php-1.32.0-wmf.22/extensions/ContentTranslation/api/ApiQueryContentTranslation.php(24): ApiQueryContentTranslation->run()
#2 /srv/mediawiki/php-1.32.0-wmf.22/includes/api/ApiQuery.php(249): ApiQueryContentTranslation->execute()
#3 /srv/mediawiki/php-1.32.0-wmf.22/includes/api/ApiMain.php(1587): ApiQuery->execute()
#4 /srv/mediawiki/php-1.32.0-wmf.22/includes/api/ApiMain.php(531): ApiMain->executeAction()
#5 /srv/mediawiki/php-1.32.0-wmf.22/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#6 /srv/mediawiki/php-1.32.0-wmf.22/api.php(87): ApiMain->execute()

Source: https://github.com/wikimedia/mediawiki-extensions-ContentTranslation/blob/81bab7d7638ac821d307013bbe9ce867d3d1beb2/api/ApiQueryContentTranslation.php#L52

$translation = Translation::find( /* .. */ );
$result->addValue( /* .. */, $translation->translation ); # Error

Notes

Example url: https://ca.wikipedia.org/w/api.php?action=query&format=json&list=contenttranslation&sourcetitle=Mikael%20Colville-Andersen&from=en&to=ca

Event Timeline

Krinkle renamed this task from ContentTranslation API emits PHP error "Cannot access property on non-object" from some queries}} to ContentTranslation API emits PHP error "Cannot access property on non-object" from some queries.Sep 21 2018, 6:46 PM
			if ( $params['sourcetitle'] && $params['from'] && $params['to'] ) {
				$translation = Translation::find(
					$params['from'], $params['to'], $params[ 'sourcetitle' ]
				);

				$result->addValue(
					[ 'query', 'contenttranslation' ],
					'translation',
					$translation->translation
				);
			}

Translation::find can return null and than $translation->translation fails

It should emit a apierror-cx-translationnotfound or apierror-invalidtitle or a new error code, I have no knowledge what the best is, but the api should handle the case when there are invalid translation given to the module. Please have a look at other api modules using Translation::findForTranslator or Translation::find to add missing null checks as well

mmodell changed the subtype of this task from "Task" to "Production Error".Aug 28 2019, 11:08 PM