Page MenuHomePhabricator

Pywikibot does not handle Wikibase "wikibase-validator-sitelink-conflict" error
Open, Needs TriagePublic

Description

Pywikibot does not yet handle the wikibase-validator-sitelink-conflict error, which occurs when a user attempts to adds a sitelink that is already in use. Here is sample traceback:

WARNING: API error failed-save: The save has failed.
Traceback (most recent call last):
  File "/srv/paws/pwb/pywikibot/page/__init__.py", line 117, in handle
    func(self, *args, **kwargs)
  File "/srv/paws/pwb/pywikibot/page/__init__.py", line 4203, in editEntity
    super().editEntity(data, **kwargs)
  File "/srv/paws/pwb/pywikibot/page/__init__.py", line 3931, in editEntity
    self, data, baserevid=baserevid, **kwargs)
  File "/srv/paws/pwb/pywikibot/tools/__init__.py", line 1481, in wrapper
    return obj(*__args, **__kw)
  File "/srv/paws/pwb/pywikibot/site/_decorators.py", line 94, in callee
    return fn(self, *args, **kwargs)
  File "/srv/paws/pwb/pywikibot/site/__init__.py", line 6034, in editEntity
    return req.submit()
  File "/srv/paws/pwb/pywikibot/data/api.py", line 1982, in submit
    raise APIError(**result['error'])
pywikibot.data.api.APIError: failed-save: The save has failed.
[messages: [{'name': 'wikibase-api-failed-save', 'parameters': [], 'html': {'*': 'The save has failed.'}}, {'name': 'wikibase-validator-sitelink-conflict', 'parameters': ['[https://commons.wikimedia.org/wiki/Category:Media_contributed_by_Dublin_Public_Library commonswiki:Category:Media contributed by Dublin Public Library]', '[[Q104440260|Q104440260]]'], 'html': {'*': 'Site link <a class="external text" href="https://commons.wikimedia.org/wiki/Category:Media_contributed_by_Dublin_Public_Library">commonswiki:Category:Media contributed by Dublin Public Library</a> is already used by item <a href="/wiki/Q104440260" title="Q104440260">Q104440260</a>. Perhaps the items should be <a href="/wiki/Special:MyLanguage/Help:Merge" title="Special:MyLanguage/Help:Merge">merged</a>.  Ask at <a href="/wiki/Wikidata:Interwiki_conflicts" title="Wikidata:Interwiki conflicts">d:Wikidata:Interwiki conflicts</a> if you believe that they should not be merged.'}}];
 help: See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "catdpla.py", line 51, in <module>
    item.editEntity(data, summary=u'Create new Wikimedia Commons category item.')
  File "/srv/paws/pwb/pywikibot/page/__init__.py", line 138, in wrapper
    handle(func, self, *args, **kwargs)
  File "/srv/paws/pwb/pywikibot/page/__init__.py", line 130, in handle
    raise pywikibot.OtherPageSaveError(self, err)
pywikibot.exceptions.OtherPageSaveError: Edit to page [[wikidata:-1]] failed:
failed-save: The save has failed.
[messages: [{'name': 'wikibase-api-failed-save', 'parameters': [], 'html': {'*': 'The save has failed.'}}, {'name': 'wikibase-validator-sitelink-conflict', 'parameters': ['[https://commons.wikimedia.org/wiki/Category:Media_contributed_by_Dublin_Public_Library commonswiki:Category:Media contributed by Dublin Public Library]', '[[Q104440260|Q104440260]]'], 'html': {'*': 'Site link <a class="external text" href="https://commons.wikimedia.org/wiki/Category:Media_contributed_by_Dublin_Public_Library">commonswiki:Category:Media contributed by Dublin Public Library</a> is already used by item <a href="/wiki/Q104440260" title="Q104440260">Q104440260</a>. Perhaps the items should be <a href="/wiki/Special:MyLanguage/Help:Merge" title="Special:MyLanguage/Help:Merge">merged</a>.  Ask at <a href="/wiki/Wikidata:Interwiki_conflicts" title="Wikidata:Interwiki conflicts">d:Wikidata:Interwiki conflicts</a> if you believe that they should not be merged.'}}];
 help: See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.OtherPageSaveError'>

Event Timeline

I think this is T61973. I believe Pywikibot should not handle this exception in any way (but a dedicated subclass wouldn't harm).