Page MenuHomePhabricator

WikibaseClient wblistentityusage API module throws RuntimeException when used as generator
Open, Needs TriagePublic

Description

As a Wikidata editor, I want to be able to query for entity usage in SPARQL, through MWAPI. (Brought up here.)
As a developer, I want API modules that advertise themselves as being possible generators to be usable as generators, instead of producing errors in production.

Problem:
Wikibase Client’s wblistentityusage Action API module produces a RuntimeException when it’s used as a generator.

Example:
https://en.wikipedia.org/w/api.php?action=query&format=json&generator=wblistentityusage&gwbeuentities=Q1&gwbeulimit=1

RuntimeException from line 306 of /srv/mediawiki/php-1.35.0-wmf.34/includes/api/ApiResult.php: Conflicting keys (31880) when attempting to merge element pages
#0 /srv/mediawiki/php-1.35.0-wmf.34/includes/api/ApiResult.php(412): ApiResult::setValue(array, string, array, integer)
#1 /srv/mediawiki/php-1.35.0-wmf.34/includes/api/ApiQuery.php(426): ApiResult->addValue(string, string, array)
#2 /srv/mediawiki/php-1.35.0-wmf.34/includes/api/ApiQuery.php(251): ApiQuery->outputGeneralPageInfo()
#3 /srv/mediawiki/php-1.35.0-wmf.34/includes/api/ApiMain.php(1583): ApiQuery->execute()
#4 /srv/mediawiki/php-1.35.0-wmf.34/includes/api/ApiMain.php(523): ApiMain->executeAction()
#5 /srv/mediawiki/php-1.35.0-wmf.34/includes/api/ApiMain.php(494): ApiMain->executeActionWithErrorHandling()
#6 /srv/mediawiki/php-1.35.0-wmf.34/api.php(84): ApiMain->execute()
#7 /srv/mediawiki/w/api.php(3): require(string)
#8 {main}

The number of conflicting keys (apparently page IDs) reported varies with the gwbeulimit:
https://en.wikipedia.org/w/api.php?action=query&format=json&generator=wblistentityusage&gwbeuentities=Q1&gwbeulimit=5

Conflicting keys (31880, 23674715) when attempting to merge element pages

Screenshots/mockups:

BDD
GIVEN
AND
WHEN
AND
THEN
AND

Acceptance criteria:

  • The API module can be used as a generator.

Open questions:

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 3 2020, 10:19 AM

Change 608920 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/extensions/Wikibase@master] Fix result for api module wblistentityusage

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/ /608920

To be usable as generator you have to extends ApiQueryGeneratorBase, that is done. You have to implment executeGenerator, that is done.

Conflicting keys (31880, 23674715) when attempting to merge element pages

31880 is the id of the page you have to list

23674715 seems to be the pageid of the next page.
31880 has currently 4 aspects, so setting the limit to 4 gives a continue with 23674715 - https://en.wikipedia.org/w/api.php?action=query&format=json&list=wblistentityusage&wbeuentities=Q1&wbeulimit=4

It seems you are mixing the current and the next pageids, when using limit = 4 it gives the wrong title/pageid in the result. (Key for query.pages is 31880, but the title/pageid shows 23674715)

{
    "batchcomplete": "",
    "continue": {
        "wbeucontinue": "23674715|Q1|L.en",
        "continue": "-||"
    },
    "query": {
        "pages": {
            "31880": {
                "ns": 2,
                "title": "User:GAllegre",
                "pageid": 23674715,
                "wblistentityusage": {
                    "Q1": {
                        "aspects": [
                            "C",
                            "O",
                            "S",
                            "T"
                        ]
                    }
                }
            }
        }
    }
}

The last group is using the wrong $row:

		if ( $entry ) {
			$this->formatPageData( $row, $currentPageId, $entry, $result );
		}

Have not tested the patch set