Page MenuHomePhabricator

wbcheckconstraints API failure: ContemporaryChecker.php Call to getStatements() on non-object
Closed, ResolvedPublic3 Story Points

Description

Campsite task

As well as fixing this one stacktrace, all other "Checker"s should have their checkConstraint method checked for a similar issue.

Error Report

Error

Request ID: W@Ic1gpAIDwAAC08Gs4AAACW

message
BadMethodCallException: Call to a member function getStatements() on a non-object (null)
trace
#0 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/ConstraintCheck/DelegatingConstraintChecker.php(553): WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ContemporaryChecker->checkConstraint(WikibaseQuality\ConstraintReport\ConstraintCheck\Context\MainSnakContext, WikibaseQuality\ConstraintReport\Constraint)
#1 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/ConstraintCheck/DelegatingConstraintChecker.php(447): WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker->getCheckResultFor(WikibaseQuality\ConstraintReport\ConstraintCheck\Context\MainSnakContext, WikibaseQuality\ConstraintReport\Constraint)
#2 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/ConstraintCheck/DelegatingConstraintChecker.php(362): WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker->checkConstraintsForMainSnak(Wikibase\DataModel\Entity\Item, Wikibase\DataModel\Statement\Statement, NULL, array)
#3 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/ConstraintCheck/DelegatingConstraintChecker.php(334): WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker->checkStatement(Wikibase\DataModel\Entity\Item, Wikibase\DataModel\Statement\Statement, NULL, array)
#4 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/ConstraintCheck/DelegatingConstraintChecker.php(154): WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker->checkEveryStatement(Wikibase\DataModel\Entity\Item, NULL, array)
#5 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/Api/CheckingResultsSource.php(54): WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker->checkAgainstConstraintsOnEntityId(Wikibase\DataModel\Entity\ItemId, NULL, array, array)
#6 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/Api/CachingResultsSource.php(247): WikibaseQuality\ConstraintReport\Api\CheckingResultsSource->getResults(array, array, NULL, array)
#7 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/Api/CachingResultsSource.php(179): WikibaseQuality\ConstraintReport\Api\CachingResultsSource->getAndStoreResults(array, array, NULL, array)
#8 /srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/Api/CheckConstraints.php(181): WikibaseQuality\ConstraintReport\Api\CachingResultsSource->getResults(array, array, NULL, array)
#9 /srv/mediawiki/php-1.33.0-wmf.2/includes/api/ApiMain.php(1570): WikibaseQuality\ConstraintReport\Api\CheckConstraints->execute()
#10 /srv/mediawiki/php-1.33.0-wmf.2/includes/api/ApiMain.php(531): ApiMain->executeAction()
#11 /srv/mediawiki/php-1.33.0-wmf.2/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#12 /srv/mediawiki/php-1.33.0-wmf.2/api.php(87): ApiMain->execute()

Impact

Certain user queries for wbcheckconstraints API consistently fail with a generic "Internal api error" exception.

Notes

WMF Logstash contains entries for this error description since at least 30 days (1.32.0-wmf.24 or earlier).

For example: https://www.wikidata.org/w/api.php?action=wbcheckconstraints&format=json&id=Q2518823.

See also: T128342

Event Timeline

Krinkle created this task.Nov 7 2018, 12:39 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 7 2018, 12:39 AM
Krinkle updated the task description. (Show Details)Nov 7 2018, 12:47 AM
Addshore triaged this task as Normal priority.Nov 7 2018, 9:45 AM
Addshore moved this task from incoming to consider for next sprint on the Wikidata board.
Addshore moved this task from Incoming to Ready to estimate on the Wikidata-Campsite board.

The actual location of the error (PHP excludes it from the stack trace for reasons that escape me):

/srv/mediawiki/php-1.33.0-wmf.2/extensions/WikibaseQualityConstraints/src/ConstraintCheck/Checker/ContemporaryChecker.php:114

This corresponds to the $objectStatements assignment here:

		/** @var EntityId $subjectId */
		$subjectId = $context->getEntity()->getId();
		/** @var EntityId $objectId */
		$objectId = $snak->getDataValue()->getEntityId();
		/** @var Statement[] $subjectStatements */
		$subjectStatements = $context->getEntity()->getStatements()->toArray();
		/** @var Statement[] $objectStatements */
		$objectStatements = $this->entityLookup->getEntity( $objectId )->getStatements()->toArray();
		/** @var String[] $startPropertyIds */
		$startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS );
		/** @var String[] $endPropertyIds */
		$endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS );

In this case, the object item has actually been deleted, which is not supposed to happen on Wikidata (items should only be deleted if they’re not used) but isn’t prevented on a technical level, so I guess ContemporaryChecker needs to guard against it. (If I recall correctly, several other checkers already include such guards.)

Addshore updated the task description. (Show Details)Nov 13 2018, 2:12 PM
Addshore set the point value for this task to 3.

Change 473549 had a related patch set uploaded (by Michael Große; owner: Michael Große):
[mediawiki/extensions/WikibaseQualityConstraints@master] Prevent exception in checker for deleted items

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

ContemporaryChecker had the only call for \Wikibase\DataModel\Services\Lookup\EntityLookup::getEntity that wasn't guarded against a null result.

Change 473549 merged by jenkins-bot:
[mediawiki/extensions/WikibaseQualityConstraints@master] Prevent exception in checker for deleted items

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

Not sure how much verification this needs – do we want to wait until the fix is deployed (two weeks), and then see if the logstash errors disappear?

Not sure how much verification this needs – do we want to wait until the fix is deployed (two weeks), and then see if the logstash errors disappear?

Yup, I think that is a good idea :)

Lucas_Werkmeister_WMDE closed this task as Resolved.Dec 3 2018, 2:55 PM

No more errors in Logstash since the 29th, when Wikidata went back on wmf.6 (after some unrelated issues). Checking constraints on Q2518823 works now (and the item still features a value for a deleted item). Looks fixed to me.

Restricted Application added a project: User-Michael. · View Herald TranscriptDec 3 2018, 2:55 PM