Page MenuHomePhabricator

Lua functions do not resolve redirects
Closed, ResolvedPublic13 Estimated Story Points

Description

In a module debug console on a Wikidata client (Q404 is a redirect to Q395):

= mw.wikibase.label('Q404')
nil
= mw.wikibase.getEntity('Q404')
table
= mw.wikibase.getEntity('Q404').id
Q395
= mw.wikibase.label('Q395')
matematika

Loading labels doesn't resolve the redirect, while loading the whole entity does.

Acceptance criteria:

  • LUA functions do resolve redirects (some of this is done in patches of unrelated tickets?)
  • Test for LUA functions resolving redirects
  • Check if the connected subtasks are still relevant. Close the ones that are done. - T142950, T104446, T127169

Related Objects

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

T143970 seems like it was recently closed but I still think we need a resolveEntityId(eid) that returns nil when there is no such entity but redirects for merged items, etc. It could also potentially work like resolvePropertyId and return a valid entity ID when given an unambiguous label or alias.

This might get resolved by T112658.

Tested it (for label) with the patchset suggested in T112658 but this will not resolve it - requiring a different fix as part of T142950

I don't understand why this doesn't have high priority. It makes the functions mw.wikibase.getLabel( id ), mw.wikibase.getDescription( id ), and mw.wikibase.getSitelinkl( id ) unreliable for IDs obtained from a module's arguments or from statement values of type wikibase-entityid in other entities.

Thus you are forced to use the expensive mw.wikibase.getEntity( id ) and entity:getLabel(), entity:getDescription(), and entity:getSitelink() to get reliable results.

Mike_Peel raised the priority of this task from Medium to High.Jul 10 2019, 5:56 PM
Mike_Peel added subscribers: RexxS, Mike_Peel.

We've just come across this issue on Commons, see discussion at https://commons.wikimedia.org/w/index.php?title=Template_talk:Wikidata_Infobox&oldid=357725187#following_redirects_on_wikidata . I've increased it to high priority.

I've come across this issue when using Template:Wikidata_list / ListeriaBot.
If an item in the list contains a reference to a WD object that was merged to another one, the label is not shown.

Examples can be found here: https://es.wikipedia.org/w/index.php?title=Usuario:Tomukas/Obra/Anexo:Diputados_de_la_XIII_legislatura_de_Espa%C3%B1a&oldid=119579608

Apparently, this has already been fixed for some functions (wb_terms normalization is probably behind this):

= mw.wikibase.getEntity('Q75288208').id
Q62568
= #mw.wikibase.getAllStatements('Q75288208', 'P31')
1
= #mw.wikibase.getBestStatements('Q75288208', 'P31')
1
= mw.wikibase.getLabel('Q75288208')
Ota IV. Braniborský
= mw.wikibase.getDescription('Q75288208')
Margrave of Brandenburg
= mw.wikibase.getLabelByLang('Q75288208', 'en')
nil
= mw.wikibase.getSitelink('Q75288208')
nil

Having some regression test would be good. Note the inconsistency between getLabel and getLabelByLang.

I went and looked through the code and it doesn't look like anything has changed here in the last years regarding the entity lookup and revision resolving specifically for LUA.

It looks like this perhaps happened with T196882 and or T229280

Having some regression test would be good.

There already is for the bits of code touched in the 2 linked ticket, although not an integration or e2e test for the high level LUA integration.

Note the inconsistency between getLabel and getLabelByLang.

IT might be worth popping that in another ticket!

Addshore lowered the priority of this task from High to Low.Apr 30 2020, 8:28 AM
Addshore updated the task description. (Show Details)

It looks like this perhaps happened with T196882 and or T229280

I think it was you in T245740 (the RedirectResolvingLatestRevisionLookup stuff?). Perhaps T127169 should get the same update as some projects may not use Lua.

  • LUA functions do resolve redirects (done in patches of unrelated tickets?)

Note that both mw.wikibase.getLabelByLang and mw.wikibase.getSitelink don't work. So it's partly (mostly) done.

I just came here to report this issue, but apparently it has been known for a while. An issue was reported at c:Template_talk:Label, so I began testing. I wrote

function p.testRedirect2(frame)
	local id       = frame.args[1]
	local entity   = mw.wikibase.getEntity(id)
	local label0   =  entity:getLabel() or 'none'
	local label1,_ =  entity:getLabelWithLang('en') or 'none'
	local label2   =  mw.wikibase.getLabel(id) or 'none'
	local label3   =  mw.wikibase.getLabelByLang(id,'en') or 'none'
	local label4,_ =  mw.wikibase.getLabelWithLang(id) or 'none'
	return label0 ..' / '.. label1 ..' / '.. label2 ..' / '.. label3 ..' / '.. label4
end

to test 5 ways of getting labels based on item ID and after testing it on redirected items discovered that all of them gave label of the target item except for mw.wikibase.getLabelByLang.

Task breakdown notes:

It looks like this all works just fine:

= mw.wikibase.getLabelByLang('Q404','en')
mathematics
= mw.wikibase.label('Q404')
mathematics

Update: Looks like https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/+/573565 accidentally fixed it. I can reproduce the problem locally after reverting the changes made in that patch.

Update 2:
getSitelink indeed doesn't yet resolve redirects.

= mw.wikibase.getSitelink('Q395')
Mathematics
= mw.wikibase.getSitelink('Q404')
nil

Change 681583 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] Lua: resolve redirects for `getSitelink`

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

Change 681938 had a related patch set uploaded (by Tonina Zhelyazkova; author: Tonina Zhelyazkova):

[mediawiki/extensions/Wikibase@master] Add api tests that invoke functions with a redirected item

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

Change 681938 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Add api tests that invoke functions with a redirected item

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

Change 681583 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Lua: resolve redirects for `getSitelink`

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

Change 684431 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] Show redirect target label on formatted entity values

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

Change 684431 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Show redirect target label on formatted entity values

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

Addshore claimed this task.

Looking good

= mw.wikibase.label('Q404')
mathematics
= mw.wikibase.label('Q395')
mathematics
= mw.wikibase.getEntity('Q404').id
Q395
= mw.wikibase.getEntity('Q395').id
Q395