jenkins-bot has submitted this change and it was merged.
Change subject: Don't crash when snaks-order is missing in API result ......................................................................
Don't crash when snaks-order is missing in API result
On older Wikibase versions, snaks-order is not returned from the API results for the items. If this is the case, the bot crashes when it gets the data. This fix ensures compatibility with those older version of Wikibase.
Bug: T76833 Change-Id: Ic014c682443919017eb9cd57b883511a6189af91 --- M pywikibot/page.py 1 file changed, 9 insertions(+), 1 deletion(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 8df644f..192d3e1 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -3624,7 +3624,15 @@ @return: dict """ source = OrderedDict() - for prop in data['snaks-order']: + + # Before #84516 Wikibase did not implement snaks-order. + # https://gerrit.wikimedia.org/r/#/c/84516/ + if 'snaks-order' in data: + prop_list = data['snaks-order'] + else: + prop_list = data['snaks'].keys() + + for prop in prop_list: for claimsnak in data['snaks'][prop]: claim = Claim.fromJSON(site, {'mainsnak': claimsnak, 'hash': data['hash']})
pywikibot-commits@lists.wikimedia.org