Page MenuHomePhabricator

.getSources() only works once per Item
Open, Needs TriagePublicBUG REPORT

Description

Steps to Reproduce:
Use a repo to a site and find an Item with referenced claims. The first time you index a claim and run .getSources() it will produce a claim of its own. After that it will only ever produce an empty list, even if you run it on a difference referenced claim on the same Item. You can run it once per Item but after it only ever returns an empty list.

Actual Results:

[OrderedDict([('P28', [Claim.fromJSON(DataSite("komorido", "komorido"), {'snaktype': 'value', 'property': 'P28', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 21}, 'type': 'wikibase-entityid'}, 'hash': '1eff422c8858dd02c904b0fae03e042baffee67e'})])])]
[]

Expected Results:

[OrderedDict([('P28', [Claim.fromJSON(DataSite("komorido", "komorido"), {'snaktype': 'value', 'property': 'P28', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 21}, 'type': 'wikibase-entityid'}, 'hash': '1eff422c8858dd02c904b0fae03e042baffee67e'})])])]
[OrderedDict([('P28', [Claim.fromJSON(DataSite("komorido", "komorido"), {'snaktype': 'value', 'property': 'P28', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 21}, 'type': 'wikibase-entityid'}, 'hash': '1eff422c8858dd02c904b0fae03e042baffee67e'})])])]

Related Objects

Event Timeline

DNations.jp renamed this task from .getSources() only wors once per Item to .getSources() only works once per Item.Nov 20 2020, 9:44 AM
DNations.jp renamed this task from .getSources() only works once per Item to .getSources() only wors once per Item.
DNations.jp renamed this task from .getSources() only wors once per Item to .getSources() only works once per Item.

@DNations.jp: Could you please provide each single step to reproduce e.g.

site = pywikibot.Site()
repo = site.data_repository()
prop = pywikibot.PropertyPage(Repro, 'P28')
...

This was my code:

import pywikibot as pwb

site = pwb.Site()
site.login()
repo = site.data_repository()
for claim in pwb.ItemPage(repo, "Q92").get()['claims']['P8']:
    print(type(claim), claim.getSources())

I was able to get the sources only once per ItemPage, even if there were multiple claims with references on an item. The only way to get it to work again was to recreate the page.

Using:
pywikibot version 5.1.0
Python version 3.8.6 via Spyder 4.2.0

Wikimedia installation:
MediaWiki 1.31.1
PHP 7.4.3 (fpm-fcgi)
MySQL 5.7.31-log
ICU 66.1
Elasticsearch 5.6.16

This is my output after running it twice.

image.png (239×1 px, 30 KB)

This was my code:

The steps to reproduce are not complete, you mentioned a "second run" and I'd like to know how that looks like. (Also you are probably running on a private repo. It would be nice if you could reproduce it on wikidata.org.)

Wikimedia installation:
MediaWiki 1.31.1

This might be too old for Wikibase but it shouldn't matter.

I just ran the script twice without changing anything and it produced an empty list the second time.

This doesn't happen with the 'claims' value after .get(). I assumed .getSources() should have the same behavior.

I will try to make the script work with wikidata.org.

It appears that .getSources() works fine on wikidata, which means the problem is on our private repo. Upgrading the version is a little complicated for our setup but hopefully that will fix the problem. Thanks!

site = pwb.Site()
#site.login()
repo = site.data_repository()
for claim in pwb.ItemPage(repo, "Q92").get()['claims']['P391']:
    print(type(claim), claim.getSources())

image.png (300×1 px, 45 KB)

Running the same script twice should deliver the same result. If not I would say this is not pywikibot related but caused by the wikibase api then. No idea what we can do on pywikibot side.

You may get a better idea about what's going on by also doing print(item._content).

I tried claim.getSources()._content and claim._content, and they both produced attribute errors.

AttributeError: 'list' object has no attribute '_content'
AttributeError: 'Claim' object has no attribute '_content'

Anyway, I think I'll write it off as an API/MediaWiki problem and not worry about it for now. Thank you.

I really meant item._content. You can also print claim.toJSON().