Page MenuHomePhabricator

Lua functions do not resolve redirects
Open, LowPublic

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 (done in patches of unrelated tickets?)
  • Test for LUA functions resolving redirects

Related Objects

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptFeb 11 2017, 1:51 PM
Lydia_Pintscher moved this task from incoming to ready to go on the Wikidata board.May 5 2017, 3:27 PM
Lydia_Pintscher added a subscriber: hoo.
Lydia_Pintscher triaged this task as Medium priority.Jun 11 2017, 4:45 PM
Larske added a subscriber: Larske.Jan 5 2018, 12:59 AM
Salgo60 added a subscriber: Salgo60.Jan 5 2018, 4:54 AM
hoo moved this task from Incoming to To do next on the Wikibase-Lua board.Apr 12 2018, 1:57 PM
Uzume added a subscriber: Uzume.Apr 12 2018, 2:56 PM

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.

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.

Ahecht added a subscriber: Ahecht.Oct 4 2018, 11:01 PM
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

matej_suchanek added a comment.EditedApr 15 2020, 8:35 AM

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)
Addshore moved this task from Needs Tech Work to Prioritized Tech on the Wikidata-Campsite board.

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.

Jarekt added a subscriber: Jarekt.May 1 2020, 12:49 PM

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.