Page MenuHomePhabricator

mw.wikibase.entityExists returns false for redirected entities
Closed, ResolvedPublic5 Estimated Story Points

Description

Problem
GIVEN Q123 is redirect entity
When I call mw.wikibase.entityExists('Q123')
Then I get false in return

Acceptance Criteria
GIVEN Q123 is redirect entity
When I call mw.wikibase.entityExists('Q123')
Then I must get true in return

Notes
Most ground work is done already as part of T112658: [Task] WikiPageEntityRevisionLookup::getLatestRevisionId() should throw an UnsersolvedRedirectException when encountering a redirect. .

Status: Investigated briefly and confirmed the problem still happens as of August 2019.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

This should probably be handled more generally along the lines of T157868 and T127169. This is exactly why I felt it was better to implement a mw.wikibase.resolveEntityId that returns the resolved eid or nil if it does not exist rather than just the true or false of mw.wikibase.entityExists. If we had a mw.wikibase.resolveEntityId we could funnel all code through it that needed to check for existence and redirection instead of making every other function handle redirection, etc.

Currently I believe the only way to check for existence and redirection from Scribunto is via the heavy mw.wikibase.getEntity and we can soon check for existence with the new and undocumented mw.wikibase.entityExists, however, fixing it to handle redirection is not highly useful without being able to ascertain the redirection target or having all functions handle redirection. I personally prefer handling all redirection and existence via a single mw.wikibase.resolveEntityId type of function vs. having all the other functions that touch entities handling redirection. This forces coders to use the redirected target eids in all the other functions that do not handle redirection and existence vs. letting them continue to use old redirecting eids. The alternative is to have all functions handle redirection.

Change 433952 had a related patch set uploaded (by Eranroz; owner: Eranroz):
[mediawiki/extensions/Wikibase@master] getLatestRevisionId redirect handling

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

Change 453118 had a related patch set uploaded (by Aleksey Bekh-Ivanov (WMDE); owner: Aleksey Bekh-Ivanov (WMDE)):
[mediawiki/extensions/Wikibase@master] Introduce LatestRevisionIdResult

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

Change 453148 had a related patch set uploaded (by Aleksey Bekh-Ivanov (WMDE); owner: Aleksey Bekh-Ivanov (WMDE)):
[mediawiki/extensions/Wikibase@master] Use LatestRevisionIdResult in EntityRevisionLookup::getLatestRevisionId

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

Change 453118 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Introduce LatestRevisionIdResult

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

Change 453148 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Use LatestRevisionIdResult in EntityRevisionLookup::getLatestRevisionId

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

Is there anything left to do here or can it be closed?

Is there anything left to do here or can it be closed?

What was the intended resolution? mw.wikibase.entityExists('Q404') still returns false.

alaa_wmde subscribed.

Let's check this and figure out what its status is.. it's been hanging around for a while and might be resolved already.

It still happens: (tested in beta cluster)

print(mw.wikibase.entityExists('Q478306'))
false
print(mw.wikibase.entityExists('Q478307'))
true

The look that is being passed to EntityAccessor is indeed RedirectResolvingEntityLookup but it can't understand redirects

ladsgroup@deployment-deploy01:~$ mwscript eval.php --wiki=enwiki
> $client = Wikibase\Client\WikibaseClient::getDefaultInstance()->getStore()->getEntityLookup();

> echo $client->hasEntity( new Wikibase\DataModel\Entity\ItemId( 'Q478306'));

> echo $client->hasEntity( new Wikibase\DataModel\Entity\ItemId( 'Q478307'));
1
> echo get_class( $client);
Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup

Broken in production as well:

ladsgroup@mwmaint1002:~$ mwscript eval.php --wiki=enwiki
> $client = Wikibase\Client\WikibaseClient::getDefaultInstance()->getStore()->getEntityLookup();

> echo $client->hasEntity( new Wikibase\DataModel\Entity\ItemId( 'Q400322'));

> echo $client->hasEntity( new Wikibase\DataModel\Entity\ItemId( 'Q17604838'));
1
>
eranroz subscribed.

Removing myself as asignee (https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/Wikibase/+/453148/ by Aleksey was merged more than 0.5 year ago and my gerrit item https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/Wikibase/+/433952/ which use RevisionedUnresolvedRedirectException in WikiPageEntityRevisionLookup::getLatestRevisionId seems less relevant)

darthmon_wmde set the point value for this task to 5.Aug 6 2019, 12:15 PM
Lydia_Pintscher raised the priority of this task from Medium to High.Aug 31 2019, 7:37 PM

So quick question from people who need this (ping @Uzume and @eranroz): Should mw.wikibase.entityExists('Q123') return true in case Q123 is redirect all the time or when it's redirecting to an existing entity?

Change 534394 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/extensions/Wikibase@master] Make RevisionBasedEntityLookup throw redirect exception on redirects

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

Change 534394 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Make RevisionBasedEntityLookup throw redirect exception on redirects

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

Change 433952 abandoned by Addshore:
getLatestRevisionId redirect handling

Reason:
I'm going to abandon this for now and continue discussing on the ticket.

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

Maintenance_bot moved this task from Incoming to In progress on the User-Ladsgroup board.
Maintenance_bot moved this task from In progress to Done on the User-Ladsgroup board.

So quick question from people who need this (ping @Uzume and @eranroz): Should mw.wikibase.entityExists('Q123') return true in case Q123 is redirect all the time or when it's redirecting to an existing entity?

That is a very good question. Since "Exists" is in "entityExists", I suppose it ought to test for existence but that makes it only marginally useful and why I asked for a consolidated method of handling the resolution of redirects vs. attempting to making the rest of the API handle redirects (which is likely error prone and hides what is really going on).