Page MenuHomePhabricator

KeyError when log event content is hidden
Closed, ResolvedPublic

Description

KeyError: "Log entry (rights) has no 'rights' key" occurs when a log event's content has been hidden (revision deletion).

The newgroups (or new) keys do not exist in params in this case.

Example response with parts of the log event hidden
{
    "batchcomplete": "",
    "query": {
        "logevents": [
            {
                "logid": 89126214,
                "actionhidden": "",
                "type": "rights",
                "action": "rights",
                "userhidden": "",
                "timestamp": "2018-02-16T09:09:40Z",
                "comment": "Confirmed as recently active IP. Granting 'confirmed' flag manually."
            }
        ]
    }
}
Code to reproduce
>>> site = pywikibot.Site('en', 'wikipedia')
>>> rights_event = next(iter(site.logevents(logtype='rights', start='20180216090941', total=1)))
>>> rights_event
<RightsEntry(wikipedia:en, logid=89126214)>
>>> rights_event.data
{'type': 'rights', 'logid': 89126214, 'userhidden': '', 'action': 'rights', 'timestamp': '2018-02-16T09:09:40Z', 'comment': "Confirmed as recently active IP. Granting 'confirmed' flag manually.", 'actionhidden': ''}
>>> rights_event.newgroups
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/shared/pywikipedia/core/pywikibot/logentries.py", line 280, in newgroups
    if 'new' in self._params:  # old mw style
  File "/shared/pywikipedia/core/pywikibot/logentries.py", line 87, in _params
    return self.data[self._expectedType]
  File "/shared/pywikipedia/core/pywikibot/logentries.py", line 34, in __missing__
    raise KeyError("Log entry (%s) has no '%s' key" % (self._type, key))
KeyError: "Log entry (rights) has no 'rights' key"

Event Timeline

This comment was removed by JJMC89.

This is apparently due to a rights log event's content being hidden (revision deletion).

JJMC89 renamed this task from Log entry (rights) has no 'rights' key to KeyError when log event content is hidden.Feb 18 2018, 2:46 AM
JJMC89 removed a project: MediaWiki-Action-API.
JJMC89 updated the task description. (Show Details)

Can this be handled gracefully in Pywikibot?

Do you have some minimum code to reproduce this issue?

Do you have some minimum code to reproduce this issue?

I've added it to the task.

Xqt triaged this task as High priority.Feb 26 2018, 11:41 AM

Can this be handled gracefully in Pywikibot?

Sure. What would be a gracefull response?

See also T78152

I guess this is a duplicate of that.


Can this be handled gracefully in Pywikibot?

Sure. What would be a gracefull response?

When attempting to access data from a log event the API response data should be checked for keys that indicate the data is hidden/suppressed. If the relevant key (see below) is present and the user doesn't have the rights to view it (it will not be in the response), raise an exception like UserRightsError.

From mw:API:Logevents#Results:

  • actionhidden: Boolean indicating the title was hidden. ns and title will be absent if the user has no sufficient rights to view deleted log entries.
  • commenthidden: Boolean indicating the comment was hidden. comment will be absent if the user has no sufficient rights to view deleted log entries.
  • userhidden: Boolean indicating the user was hidden. user and userid will be absent if the user has no sufficient rights to view deleted log entries.
  • suppressed: Boolean indicating details were supressed. Only users with the suppressrevision can view them.

actionhidden also hides params.


This would also apply to trying to get hidden/suppressed data about a revision.

  • texthidden: Boolean indicating the text was hidden.
  • userhidden: Boolean indicating the user was hidden. user and userid will be absent if the user has no sufficient rights to view deleted log entries.
  • commenthidden: Boolean indicating the comment was hidden. comment will be absent if the user has no sufficient rights to view deleted log entries.
  • suppressed: Boolean indicating details were supressed. Only users with the suppressrevision can view them.

See also T78152

I guess this is a duplicate of that.

It isn’t. This couldn’t be solved by the other patch. But it is similar due to hidden information.

Change 421805 had a related patch set uploaded (by JJMC89; owner: JJMC89):
[pywikibot/core@master] [IMPR] LogDict: Raise UserRightsError when part of a log event is hidden

https://gerrit.wikimedia.org/r/421805

@Xqt

API request
{
	"action": "query",
	"format": "json",
	"list": "logevents",
	"letype": "delete"
}
One event in response while logged out
{
    "logid":339405,
    "actionhidden":"",
    "type":"delete",
    "action":"delete",
    "user":"Example",
    "timestamp":"2016-03-21T00:00:00Z",
    "commenthidden":""
}
Above as a sysop
{
    "logid":339405,
    "actionhidden":"",
    "ns":0,
    "title":"Order 1-(3-methylphenyl)-2-(methylamino)propan-1-one (3mmc)",
    "pageid":0,
    "type":"delete",
    "action":"delete",
    "user":"Example",
    "timestamp":"2016-03-21T00:00:00Z",
    "commenthidden":"",
    "comment":"content was: \"{{Spam || Splitting Bad displays that undesireable effects your drug offers, in addition issues, but the issues your some one will get straight into with regards to that not too very good guys and also the legislation. [https://schengenl...\""
}

The comment and action are hidden, and the comment and action are in the API response when requested as a sysop.

Change 421805 merged by jenkins-bot:
[pywikibot/core@master] [IMPR] LogDict: Raise HiddenKeyError when a key is hidden

https://gerrit.wikimedia.org/r/421805

JJMC89 claimed this task.