Xqt submitted this change.

View Change

Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
[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(-)

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 change 230285. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Icaf80ed270b2fa8ffa6f2519539a47313cabc7a2
Gerrit-Change-Number: 230285
Gerrit-PatchSet: 16
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski@gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw@arctus.nl>
Gerrit-Reviewer: Multichill <maarten@mdammers.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus@gmx.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged