jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1345312?usp=email )

Change subject: [site] Raise ServerError for invalid userinfo API responses
......................................................................

[site] Raise ServerError for invalid userinfo API responses

Replace assertion checks with ServerError exceptions in the userinfo
property of APISite. Assertions should not be used to validate external
network data.

Raising ServerError ensures that callers, such as isInterwikiLink() in
CosmeticChangesToolkit, can natively suppress the exception when an
interwiki target is down or returns a 404 (which lacks the 'query' key).
This prevents the entire bot from crashing on a single bad interwiki link.

Bug: T423061
Change-Id: Ibd17422e5e1eb68ce1da32a4c6427ea34a6c7a9d
---
M pywikibot/site/_apisite.py
1 file changed, 5 insertions(+), 4 deletions(-)

Approvals:
  Mahveotm: Looks good to me, approved
  jenkins-bot: Verified
  Meno25: Looks good to me, but someone else must approve




diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 50b090f..446566f 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -43,6 +43,7 @@
     PageDeletedConflictError,
     PageRelatedError,
     PageSaveRelatedError,
+    ServerError,
     SiteDefinitionError,
     SpamblacklistError,
     TitleblacklistError,
@@ -673,10 +674,10 @@
                 formatversion=2,
             )
             uidata = uirequest.submit()
-            assert 'query' in uidata, \
-                   "API userinfo response lacks 'query' key"
-            assert 'userinfo' in uidata['query'], \
-                   "API userinfo response lacks 'userinfo' key"
+            if 'query' not in uidata:
+                raise ServerError("API userinfo response lacks 'query' key")
+            if 'userinfo' not in uidata['query']:
+                raise ServerError("API userinfo response lacks 'userinfo' key")
             self._userinfo = uidata['query']['userinfo']
             if self._loginstatus != login.LoginStatus.IN_PROGRESS \
                and ('anon' in self._userinfo or not self._userinfo.get('id')):

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1345312?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ibd17422e5e1eb68ce1da32a4c6427ea34a6c7a9d
Gerrit-Change-Number: 1345312
Gerrit-PatchSet: 2
Gerrit-Owner: Aruotes <[email protected]>
Gerrit-Reviewer: Mahveotm <[email protected]>
Gerrit-Reviewer: Meno25 <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to