Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/230285 )

Change subject: [FIX] BlockEntry constructor fails for hidden title
......................................................................

[FIX] BlockEntry constructor fails for hidden title

- return an empty dict if 'param' is missing; test for old behaviour first
- use an empty string for autoblock detection if title is hidden
- return an empty list id 'params' (and 'flags') is missing

Bug: T78152
Change-Id: Icaf80ed270b2fa8ffa6f2519539a47313cabc7a2
---
M pywikibot/logentries.py
1 file changed, 6 insertions(+), 10 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved



diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index 11c94cd..d6fe6a3 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -62,7 +62,7 @@
                 "Log entry ({}) has a hidden '{}' key and you don't have "
                 'permission to view it.'.format(self['type'], key))

-        raise KeyError("Log entry ({}) has no '{}' key"
+        raise KeyError('Log entry ({}) has no {!r} key'
                        .format(self['type'], key))

     def __repr__(self) -> str:
@@ -95,9 +95,8 @@
     def _params(self) -> Dict[str, Any]:
         """Additional data for some log entry types."""
         with suppress(KeyError):
-            return self['params']
-
-        return self[self._expected_type]
+            return self[self._expected_type]  # old behaviour
+        return self.get('params', {})

     def page(self) -> Union[int, 'pywikibot.page.Page']:
         """
@@ -156,7 +155,7 @@
         super().__init__(apidata, site)
         # When an autoblock is removed, the "title" field is not a page title
         # See bug T19781
-        pos = self['title'].find('#')
+        pos = self.get('title', '').find('#')
         self.isAutoblockRemoval = pos > 0
         if self.isAutoblockRemoval:
             self._blockid = int(self['title'][pos + 1:])
@@ -186,13 +185,10 @@
         if self.action() == 'unblock':
             return []
         if not hasattr(self, '_flags'):
-            self._flags = self._params['flags']
+            self._flags = self._params.get('flags', [])
             # pre mw 1.25 returned a delimited string.
             if isinstance(self._flags, str):
-                if self._flags:
-                    self._flags = self._flags.split(',')
-                else:
-                    self._flags = []
+                self._flags = self._flags.split(',') if self._flags else []
         return self._flags

     def duration(self) -> Optional[datetime.timedelta]:

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Icaf80ed270b2fa8ffa6f2519539a47313cabc7a2
Gerrit-Change-Number: 230285
Gerrit-PatchSet: 16
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: Framawiki <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Magul <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Multichill <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to