Page MenuHomePhabricator

delete an ItemPage results in TypeError
Closed, ResolvedPublic

Description

I am trying to delete an instance of pywikibot.ItemPage using the delete function. After a recent pywikibot update to the latest version (r-pywikibot-core.git (7961cc8, g14506, 2021/03/26, 18:47:46, master)), my previously perfectly running script crashes and the trackback reads:

Traceback (most recent call last):
  File "../pywikibot/pwb.py", line 363, in <module>
    if not main():
  File "../pywikibot/pwb.py", line 358, in main
    file_package)
  File "../pywikibot/pwb.py", line 75, in run_python_file
    main_mod.__dict__)
  File "del_items.py", line 57, in <module>
    Qitem.delete(reason=editsummary, prompt=True, mark=False, quit=True)
  File "/mnt/nfs/labstore-secondary-tools-home/msyn/pywikibot/pywikibot/page/__init__.py", line 1739, in delete
    self.site.deletepage(self, reason)
  File "/mnt/nfs/labstore-secondary-tools-home/msyn/pywikibot/pywikibot/site/_decorators.py", line 93, in callee
    return fn(self, *args, **kwargs)
  File "/mnt/nfs/labstore-secondary-tools-home/msyn/pywikibot/pywikibot/tools/__init__.py", line 1445, in wrapper
    return obj(*__args, **__kw)
  File "/mnt/nfs/labstore-secondary-tools-home/msyn/pywikibot/pywikibot/site/_apisite.py", line 2073, in deletepage
    pageid = int(page)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'ItemPage'
CRITICAL: Exiting due to uncaught exception <class 'TypeError'>

I think the problem is that in pywikibot/site/_apisite.py$2069, it checks isinstance(page, pywikibot.Page), which probably evaluates to False as pywikibot.ItemPage does *not* extend pywikibot.Page (it extends pywikibot.BasePage, however).

Event Timeline

Change 675345 had a related patch set uploaded (by JJMC89; author: JJMC89):
[pywikibot/core@master] [FIX] Allow deleting any subclass of BasePage by title

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

Xqt triaged this task as High priority.Mar 29 2021, 4:25 AM
Xqt added a subscriber: Mpaa.

Change 675345 merged by jenkins-bot:
[pywikibot/core@master] [FIX] Allow deleting any subclass of BasePage by title

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