Page MenuHomePhabricator

backlinks() KeyError after creating a new custom namespace in zhwiki
Closed, ResolvedPublic

Description

backlinks() KeyError after creating a new custom namespace in zhwiki (see T271612 ):

 redirects = banner_page.backlinks(filter_redirects=True)
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/tools/__init__.py", line 1480, in wrapper
    return obj(*__args, **__kw)
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/page/__init__.py", line 1018, in backlinks
    content=content
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/tools/__init__.py", line 1480, in wrapper
    return obj(*__args, **__kw)
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/site/__init__.py", line 1854, in pagebacklinks
    if redir.getRedirectTarget() == page:
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/page/__init__.py", line 1651, in getRedirectTarget
    return self.site.getredirtarget(self)
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/site/__init__.py", line 1458, in getredirtarget
    ns = target.namespace()
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/page/__init__.py", line 251, in namespace
    return self._link.namespace
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/page/__init__.py", line 5919, in namespace
    self.parse()
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/page/__init__.py", line 5893, in parse
    if self._site.namespaces[self._namespace].case == 'first-letter':
  File "/mnt/nfs/labstore-secondary-tools-project/sz-iwbot/pywikibot/pywikibot/site/_namespace.py", line 334, in __getitem__
    return self._namespaces[key]
KeyError: 102
CRITICAL: Exiting due to uncaught exception <class 'KeyError'>

This script runs on zhwiki

Event Timeline

If this namespaces was newly added you have to clear the cache first. There are several ways:

  • clear or delete the apicache-py3 folder
  • run the maintenance script to retrieve siteinfo for wikipedia family: pwb -API_config_expiry:0 preload_sites wikipedia
  • run cache maintenence script: pwb cache -delete -c entry.site.code == "zh"
  • wait upto 30 days until the cache file is expired

But it could be a good idea to let the framework reload the siteinfo is such case

Xqt triaged this task as Medium priority.Feb 3 2021, 4:05 PM
在T273763#6800531中,@Xqt写道:

If this namespaces was newly added you have to clear the cache first. There are several ways:

Thx, clear cache is ok.

Xqt lowered the priority of this task from Medium to Lowest.Feb 4 2021, 6:00 AM

Change 662043 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [IMPR] raise a more informative KeyError in NamespacesDict.getitem

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

Change 662072 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [doc] Update documentation for Page.upload() parameters

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

Change 662072 merged by jenkins-bot:
[pywikibot/core@master] [doc] Update documentation for Page.upload() parameters

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

Xqt claimed this task.

Change 662043 merged by Xqt:
[pywikibot/core@master] [IMPR] raise a more informative KeyError in NamespacesDict.getitem

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