Page MenuHomePhabricator

Make Pywikibot not crash on new item creation bug
Closed, ResolvedPublic

Description

See https://bugzilla.wikimedia.org/show_bug.cgi?id=46535 . Everyone once in a while you'll get an apierror when trying to create a new page:

File "C:\pywikibot\core\pywikibot\page.py", line 2523, in editEntity
  baserevid=baserevid, **kwargs)
File "C:\pywikibot\core\pywikibot\site.py", line 721, in callee
  return fn(self, *args, **kwargs)
File "C:\pywikibot\core\pywikibot\site.py", line 3725, in editEntity
  data = req.submit()
File "C:\pywikibot\core\pywikibot\data\api.py", line 401, in submit
  raise APIError(code, info, **result["error"])

pywikibot.data.api.APIError: failed-save: Could not create a new page.
It already exists.
<class 'pywikibot.data.api.APIError'>

Error should be caught somewhere in the lower layers and it should be retried (just like with connection problems). It should respect maxretries so it doesn't get stuck in a loop


Version: core-(2.0)
Severity: critical
URL: https://bugzilla.wikimedia.org/show_bug.cgi?id=46535
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=46535

Details

Reference
bz62126

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 2:51 AM
bzimport set Reference to bz62126.
bzimport added a subscriber: Unknown Object (????).

Change 116280 had a related patch set uploaded by Xqt:
(bug 62126) Retry creating a new page at wikidata.

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

Change 116280 merged by jenkins-bot:
(bug 62126) Retry creating a new page at wikidata.

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

I think this bug should only force a retry if the reason the save failed is 'edit-already-exists'

i.e. pseudocode
in api.py

-if code == "failed-save" and action == 'wbeditentity':
+if code == "failed-save" and action == 'wbeditentity' and info == 'Could not create a new page.\nIt already exists.':

or

-if code == "failed-save" and action == 'wbeditentity':
+if code == "failed-save" and action == 'wbeditentity':
+ messages = result["error"].pop("messages", None)
+ if messages and messages['0'] and messages['0']['name'] == 'edit-already-exists':

The error message is 'wikibase-error-label-not-unique-item'

See also https://gerrit.wikimedia.org/r/#/c/129964/

The error we should not resubmit is 'wikibase-error-label-not-unique-item'.

The only error we should retry is 'edit-already-exists'.

That code and my pseudo-code above do the same thing, in different ways.