Page MenuHomePhabricator

warning & errors when adding claim sources
Open, Needs TriagePublic

Description

Observation
When adding a claim to an item and then edit the claim (i.e. change its rank, adding claim sources) pywikibot(latest version) logs WARNINGS

"WARNING: API warning (wbsetclaim) of unknown format: {'messages': [{'name': 'wikibase-conflict-patched', 'type': 'warning', 'parameters': [], 'html': {'*': 'Your edit was patched into the latest version.'}}]}"

or throws an Exception with message text

editconflict: Edit conflict. Could not patch the current revision. [messages:[{'name': 'wikibase-api-editconflict', 'parameters': [], 'html': {'*': 'Edit conflict. Could not patch the current revision.'}}, {'name': 'edit-conflict', 'parameters': [], 'html': {'*': 'Edit conflict.'}}]; help:See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.]

Possible cause
@matej_suchanek had a look into the framework code and suspected that after an edit has been made the item does not get updated i.e. the latest version of the item does not get pulled instead the old revision is being used which causes the error.

Workaround
After each change made to the item/claim, I pulled the latest revision of the item using something like this

latest_revsion_of_item = pywikibot.ItemPage(repo, qCode)

before making the next edit/change.

Example code causing WARNINGS and ERRORS

The following code snippet illustrates the flow causing the WARNINGS and ERRORS

alexa_ranking_claim = _get_alexa_ranking_claim(alexa_ranking)#helper method: no interaction with pywikibot.Item
item.addClaim(alexa_ranking_claim, summary=u'Updating Alexa ranking')#no issue at this line
_set_existing_alexa_rankings_to_normal(item) #no issue at this line / code loops over existing claims and sets each of them to normal using the changeRank('normal') method
alexa_ranking_claim.changeRank('preferred')#WARNING is shown here
point_in_time = _get_point_in_time_source()#helper method: no interaction with pywikibot.Item
referenced_url = _get_referenced_url_claim(official_web_page)#helper method: no interaction with pywikibot.Item
archive_url = get_url_of_archived_page(official_web_page,timestamp)#helper method: no interaction with pywikibot.Item
archive_url_claim = _get_archive_url_claim(archive_url)#helper method: no interaction with pywikibot.Item
alexa_ranking_claim.addSources([point_in_time,referenced_url,archive_url_claim], summary='Adding Alexa ranking date, reference url and archive URL.') # Exception is raised at this point / no claim sources are added

Example code avoiding WARNINGS and ERRORS

The following code snippet illustrates the flow avoiding WARNINGS and ERRORS

alexa_ranking_claim = _get_alexa_ranking_claim(alexa_ranking)#helper method: no interaction with pywikibot.Item
item.addClaim(alexa_ranking_claim, summary=u'Updating Alexa ranking')#no issue at this line
item = pywikibot.ItemPage(repo, qCode)
_set_existing_alexa_rankings_to_normal(item) #no issue at this line / code loops over existing claims and sets each of them to normal using the changeRank('normal') method
item = pywikibot.ItemPage(repo, qCode)
alexa_ranking_claim.changeRank('preferred')#no issue at this line
item = pywikibot.ItemPage(repo, qCode)
point_in_time = _get_point_in_time_source()#helper method: no interaction with pywikibot.Item
referenced_url = _get_referenced_url_claim(official_web_page)#helper method: no interaction with pywikibot.Item
archive_url = get_url_of_archived_page(official_web_page,timestamp)#helper method: no interaction with pywikibot.Item
archive_url_claim = _get_archive_url_claim(archive_url)#helper method: no interaction with pywikibot.Item
alexa_ranking_claim.addSources([point_in_time,referenced_url,archive_url_claim], summary='Adding Alexa ranking date, reference url and archive URL.') #no issue at this line / claim sources get added