jenkins-bot has submitted this change and it was merged.
Change subject: Raise exception on unknown MediaWiki exception ......................................................................
Raise exception on unknown MediaWiki exception
Some MediaWiki exceptions should be handled by backing off and retrying, however others will not resolve themselves and need to be a python exception
There was a list of three exception that caused a re-try, but d5cc2b9 removed the list and always retried when there was a MediaWiki exception.
This change effectively reverts d5cc2b9, but also adds APIMWException as a subclass of APIError, and adds information about the three exceptions which should cause an API retry.
Bug: 70754 Change-Id: I3c4d23bfc4f8feb01fc6e349d271fceb746412d8 --- M pywikibot/data/api.py 1 file changed, 32 insertions(+), 2 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 0e846ae..919b7c1 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -75,6 +75,17 @@ return self.info
+class APIMWException(APIError): + + """The API site returned an error about a MediaWiki internal exception.""" + + def __init__(self, mediawiki_exception_class_name, info, **kwargs): + """Save error dict returned by MW API.""" + self.mediawiki_exception_class_name = mediawiki_exception_class_name + code = 'internal_api_error_' + mediawiki_exception_class_name + super(APIMWException, self).__init__(code, info, **kwargs) + + class TimeoutError(Error): pass
@@ -512,6 +523,7 @@ self._handle_warnings(result) if "error" not in result: return result + if "*" in result["error"]: # help text returned result['error']['help'] = result['error'].pop("*") @@ -524,9 +536,26 @@ u"Pausing due to database lag: " + info) self.site.throttle.lag(int(lag.group("lag"))) continue + if code.startswith(u'internal_api_error_'): - self.wait() - continue + class_name = code[len(u'internal_api_error_'):] + if class_name in ['DBConnectionError', # r 4984 & r 4580 + 'DBQueryError', # bug 58158 + 'ReadOnlyError' # bug 59227 + ]: + + pywikibot.log(u'MediaWiki exception %s; retrying.' + % class_name) + self.wait() + continue + + pywikibot.log(u"MediaWiki exception %s: query=\n%s" + % (class_name, + pprint.pformat(self.params))) + pywikibot.log(u" response=\n%s" % result) + + raise APIMWException(class_name, info, **result["error"]) + # bugs 46535, 62126, 64494, 66619 # maybe removed when it 46535 is solved if code == "failed-save" and \ @@ -540,6 +569,7 @@ % pprint.pformat(self.params)) pywikibot.log(u" response=\n%s" % result) + raise APIError(code, info, **result["error"]) except TypeError: raise RuntimeError(result)
pywikibot-commits@lists.wikimedia.org