Page MenuHomePhabricator

redirect.py: problem with the build-in generator
Closed, ResolvedPublicBUG REPORT

Description

@PAWS:/srv/paws/pwb$ python pwb.py redirect double -ns:0 -fullscan  
.
Execution time: 0 seconds
Script terminated by exception:

ERROR: 'str' object has no attribute 'namespace' (AttributeError)
Traceback (most recent call last):
  File "/srv/paws/pwb/pwb.py", line 39, in <module>
    sys.exit(main())
  File "/srv/paws/pwb/pwb.py", line 35, in main
    runpy.run_path(str(path), run_name='__main__')
  File "/usr/lib/python3.10/runpy.py", line 289, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/srv/paws/pwb/pywikibot/scripts/wrapper.py", line 516, in <module>
    main()
  File "/srv/paws/pwb/pywikibot/scripts/wrapper.py", line 500, in main
    if not execute():
  File "/srv/paws/pwb/pywikibot/scripts/wrapper.py", line 487, in execute
    run_python_file(filename, script_args, module)
  File "/srv/paws/pwb/pywikibot/scripts/wrapper.py", line 147, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File "/srv/paws/pwb/scripts/redirect.py", line 742, in <module>
    main()
  File "/srv/paws/pwb/scripts/redirect.py", line 738, in main
    bot.run()
  File "/srv/paws/pwb/pywikibot/bot.py", line 1686, in run
    for item in self.generator:
  File "/srv/paws/pwb/pywikibot/pagegenerators/_filters.py", line 88, in <genexpr>
    return (page for page in generator if page.namespace() in namespaces)
AttributeError: 'str' object has no attribute 'namespace'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>

I think that it's effect of the output type in line 295: (the union)

def retrieve_broken_redirects(self) -> Generator[
        Union[str, pywikibot.Page], None, None]:

and similarly in line 319 (for the double redirects)

Event Timeline

Xqt triaged this task as High priority.Mar 6 2023, 5:51 AM
Shalomori123 renamed this task from redirect.py: problem with namespace to redirect.py: problem with the build-in generator.Mar 9 2023, 6:24 PM
Xqt changed the task status from Open to In Progress.Apr 1 2023, 10:22 AM
Xqt claimed this task.

Change 904875 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [bugfix] Fix -namespace usage if RedirectGenerator is used

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

@Xqt why to deprecate this option actually? I think the problem is in this strange generator. We have no other generator in pagegenerators that yield str() type.

I don't understand in the software efficiency of the Page() class, but I think that the solution should be to yield Page(self.site, pagetitle) instead of yield pagetitle itself... Maybe in other efficient way, but the approach to yield string can cause other problems.

I haven’t removed any option. fullscan as well as both actions uses Site.allpages which has a namespace parameter and does not need additional namespace filter. Also -xml has its own filter. yielding a page object might be a good idea anyway but needs further changes and is not related to this underlying problem. By the way namespace 0 is default for -fullscan and -xml but this dos not lock very consistent.

Change 904875 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] Fix -namespace usage if RedirectGenerator is used

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