jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[bugfix] Suppress error in CosmeticChangesToolkit.cleanUpLinks()

- no longer retry api request on ServerError which includes
FatalServerError. ServerError is raised when a requests.ReadTimeout
or requests.ConnectTimeout occurs.
- suppress ServerError in CosmeticChangesToolkit.cleanUpLinks()
when calling site.isInterwikiLink() because the corresponding
site may be down.

Bug: T337045
Change-Id: I499bc1d7cc2bbd98cac20548a5e40c9dbf314ec2
---
M pywikibot/cosmetic_changes.py
M pywikibot/data/api/_requests.py
2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 1e13373..845d6ce 100644
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -64,9 +64,8 @@
from urllib.parse import urlparse, urlunparse

import pywikibot
-from pywikibot import textlib
+from pywikibot import exceptions, textlib
from pywikibot.backports import Callable, Match, Pattern
-from pywikibot.exceptions import InvalidTitleError
from pywikibot.textlib import (
FILE_LINK_REGEX,
MultiTemplateMatchBuilder,
@@ -532,8 +531,10 @@
oldlink = url2string(match.group(),
encodings=self.site.encodings())

- is_interwiki = self.site.isInterwikiLink(titleWithSection)
- if is_interwiki:
+ is_interwiki = None
+ with suppress(exceptions.ServerError):
+ is_interwiki = self.site.isInterwikiLink(titleWithSection)
+ if is_interwiki is not False:
return oldlink

# The link looks like this:
@@ -541,10 +542,9 @@
# We only work on namespace 0 because pipes and linktrails work
# differently for images and categories.
page = pywikibot.Page(pywikibot.Link(titleWithSection, self.site))
- try:
+ in_main_namespace = None
+ with suppress(exceptions.InvalidTitleError):
in_main_namespace = page.namespace() == 0
- except InvalidTitleError:
- in_main_namespace = False
if not in_main_namespace:
return oldlink

diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index 3b63cb2..61dad40 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -30,10 +30,10 @@
from pywikibot.exceptions import (
Client414Error,
Error,
- FatalServerError,
MaxlagTimeoutError,
NoUsernameError,
Server504Error,
+ ServerError,
SiteDefinitionError,
)
from pywikibot.login import LoginStatus
@@ -694,7 +694,7 @@
pywikibot.warning(
'Caught HTTP 414 error, although not using GET.')
raise
- except (ConnectionError, FatalServerError):
+ except (ConnectionError, ServerError):
# This error is not going to be fixed by just waiting
pywikibot.error(traceback.format_exc())
raise

To view, visit change 921582. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I499bc1d7cc2bbd98cac20548a5e40c9dbf314ec2
Gerrit-Change-Number: 921582
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Meno25 <meno25mail@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged