Page MenuHomePhabricator

site.page_restrictions doesn't return the protection when a page is create protected
Closed, ResolvedPublic

Assigned To
Authored By
JJMC89
Jan 21 2019, 10:21 AM
Referenced Files
None
Tokens
"The World Burns" token, awarded by Framawiki."Burninate" token, awarded by Dvorapa.

Description

site.page_restrictions() raises pywikibot.exceptions.NoPage when a page is create protected. For pages that do not exist, I would expect something like {'create': ('sysop', 'infinity')} for protected pages and {} for unprotected pages. This is already available in page._protection.

>>> site = pywikibot.Site('en', 'wikipedia')
>>> page = pywikibot.Page(site, 'Make a new page')
>>> page.protection()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/mnt/nfs/labstore-secondary-tools-project/pywikibot/public_html/core/pywikibot/page.py", line 1105, in protection
    return self.site.page_restrictions(self)
  File "/mnt/nfs/labstore-secondary-tools-project/pywikibot/public_html/core/pywikibot/site.py", line 3182, in page_restrictions
    raise NoPage(page)
pywikibot.exceptions.NoPage: Page [[en:Make a new page]] doesn't exist.
>>> site.loadpageinfo(page) # if needed
>>> page._protection
{'create': ('sysop', 'infinity')}

Event Timeline

page_restrictions is full of bugs, should be rewritten at all. For many protected pages it just outputs empty dict or error, not only the case you describe here

Xqt triaged this task as High priority.Jan 21 2019, 12:08 PM

Change 582522 had a related patch set uploaded (by JJMC89; owner: JJMC89):
[pywikibot/core@master] Site.page_restrictions(): Do not raise NoPage

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

Change 582522 merged by jenkins-bot:
[pywikibot/core@master] Site.page_restrictions(): Do not raise NoPage

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

JJMC89 removed a project: Patch-For-Review.