Page MenuHomePhabricator

getAllStatements does not make a copy, getBestStatements does
Closed, ResolvedPublicBUG REPORT

Description

Run the following module from the console (= p.test()):

local p = {}

function p.test()
	local entity, statements

	entity = mw.wikibase.getEntity('Q213')
	statements = entity:getAllStatements('P1082')
	mw.log(#statements)
	table.remove(statements)
	mw.log(#statements, #entity:getAllStatements('P1082'), #entity.claims.P1082)

	entity = mw.wikibase.getEntity('Q213')
	statements = entity:getBestStatements('P1082')
	mw.log(#statements)
	table.remove(statements)
	mw.log(#statements, #entity:getBestStatements('P1082'), #entity.claims.P1082)
end

return p

(table.remove performs in-place removal of the last element in the sequence.)

You will get:

35
34	34	34
1
0	1	35

In other words, changing the value returned from getAllStatements will change it for all following calls and also change the entity object.
This does not happen with getBestStatements.

Event Timeline

Change #1083819 had a related patch set uploaded (by Joely Rooke WMDE; author: Joely Rooke WMDE):

[mediawiki/extensions/Wikibase@master] Prevent getAllStatements from returning mutable entity statements

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

Change #1084127 had a related patch set uploaded (by Joely Rooke WMDE; author: Joely Rooke WMDE):

[mediawiki/extensions/Wikibase@master] Prevent getAllStatements from returning mutable entity statements

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

Change #1084127 abandoned by Joely Rooke WMDE:

[mediawiki/extensions/Wikibase@master] Prevent getAllStatements from returning mutable entity statements

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

Change #1083819 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Prevent getAllStatements from returning mutable entity statements

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