Page MenuHomePhabricator

canBeEdited method seems broken since the depreciation of the sysop argument in pywikibot.login.LoginManager.__init__
Closed, ResolvedPublic

Description

Hello, I've just updated my Pywikibot version (jump from 3.0.20180922 to 3.0.20200111) and one of my script is broken.

In a nutshell, I'm checking pages with the extended confirmed protection to add or remove a specific template. And sometimes, this template is used on protected pages.

Results with the out-of-date version:

tools.lebot@tools-sgebastion-07:~$ python3 pywikibotold/core/pwb.py pywikibot/core/scripts/userscripts/semiprotectionextended.py
ERROR: Seuls les administrateurs peuvent modifer la page : Doc Gynéco
ERROR: Seuls les administrateurs peuvent modifer la page : Falun Gong
ERROR: Seuls les administrateurs peuvent modifer la page : La Cocarde étudiante

Three articles can't be edited by the bot because the bot is not an administrator: everything is okay. I'm checking this case with the method canBeEdited() and skip the page if False.

Results with the lastest version and the same script:

tools.lebot@tools-sgebastion-07:~$ python3 pywikibot/core/pwb.py -v pywikibot/core/scripts/userscripts/semiprotectionextended.py
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516]
Found 1 wikipedia:fr processes running, including this one.
WARNING: /mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/site.py:3155: DeprecationWarning: sysop argument of pywikibot.login.LoginManager.__init__ is deprecated.
  api.LoginManager(site=self, sysop=sysop_protected)

Logging in to wikipedia:fr as Tictacbot@Tictacbot
Should be logged in now
Sleeping for 8.2 seconds, 2020-02-07 20:33:59
WARNING: API error protectedpage: This page has been protected to prevent editing or other actions.
API Error: query=
[...]

response=
{'error': {'info': 'This page has been protected to prevent editing or other actions.', 'code': 'protectedpage', 'help': 'See https://fr.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.'}, 'servedby': 'mw1342'}
Error saving page [[Doc Gynéco]] (Page [[fr:Doc Gynéco]] is locked.)

Traceback (most recent call last):
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/site.py", line 5352, in editpage
    result = req.submit()
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/data/api.py", line 2080, in submit
    raise APIError(**result['error'])
pywikibot.data.api.APIError: protectedpage: This page has been protected to prevent editing or other actions. [help:See https://fr.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/page.py", line 112, in handle
    func(self, *args, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/page.py", line 1304, in _save
    watch=watch, bot=botflag, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/site.py", line 1319, in callee
    return fn(self, *args, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/site.py", line 5371, in editpage
    raise self._ep_errors[err.code](page)
pywikibot.exceptions.LockedPage: Page [[fr:Doc Gynéco]] is locked.Traceback (most recent call last):
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/site.py", line 5352, in editpage
    result = req.submit()
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/data/api.py", line 2080, in submit
    raise APIError(**result['error'])
pywikibot.data.api.APIError: protectedpage: This page has been protected to prevent editing or other actions. [help:See https://fr.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pywikibot/core/pwb.py", line 325, in <module>
    if not main():
  File "pywikibot/core/pwb.py", line 320, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pywikibot/core/pwb.py", line 101, in run_python_file
    main_mod.__dict__)
  File "pywikibot/core/scripts/userscripts/semiprotectionextended.py", line 58, in <module>
    retraitModele()
  File "pywikibot/core/scripts/userscripts/semiprotectionextended.py", line 53, in retraitModele
    page.save(summary="[[wp:bot|Robot]] : retrait de l'icône de semi-protection étendue", minor=True)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/tools/__init__.py", line 1744, in wrapper
    return obj(*__args, **__kw)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/tools/__init__.py", line 1744, in wrapper
    return obj(*__args, **__kw)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/page.py", line 1293, in save
    cc=apply_cosmetic_changes, quiet=quiet, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/page.py", line 133, in wrapper
    handle(func, self, *args, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/page.py", line 124, in handle
    raise err
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/page.py", line 112, in handle
    func(self, *args, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/page.py", line 1304, in _save
    watch=watch, bot=botflag, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/site.py", line 1319, in callee
    return fn(self, *args, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-project/lebot/pywikibot/core/pywikibot/site.py", line 5371, in editpage
    raise self._ep_errors[err.code](page)
pywikibot.exceptions.LockedPage: Page [[fr:Doc Gynéco]] is locked.
Dropped throttle(s).
Closing network session.
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.LockedPage'>
Network session closed.

It seems that the method canBeEdited() no longer performs the check correctly, or at least that its behaviour is no longer identical. I believe the problem comes from this change, but I'm not sure and I don't know Pywikibot source code enough to do some deep digging. Maybe I'm the one who missed a breaking change.

Event Timeline

Lofhi renamed this task from DeprecationWarning for the sysop argument in pywikibot.login.LoginManager.__init__ to canBeEdited method seems broken since the depreciation of the sysop argument in pywikibot.login.LoginManager.__init__ .Feb 7 2020, 8:50 PM
Xqt triaged this task as High priority.

Change 570994 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Rewrite APISite.page_can_be_edited

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

Change 570994 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Rewrite APISite.page_can_be_edited

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