https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
Bug ID: 72942 Summary: interwiki option causes error Product: Pywikibot Version: core (2.0) Hardware: All OS: All Status: NEW Severity: normal Priority: Unprioritized Component: pagegenerators Assignee: Pywikipedia-bugs@lists.wikimedia.org Reporter: jan.dudik@gmail.com Web browser: --- Mobile Platform: ---
D:\Py\rewrite>pwb.py replace -regex -interwiki:Category:Francouzština -family:wiktionary -regex "[[za:(.*?)]]\n" ""
Exception in thread Put-Thread: Traceback (most recent call last): File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner self.run() File "C:\Python27\lib\threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "D:\Py\rewrite\pywikibot__init__.py", line 679, in async_manager request(*args, **kwargs) File "D:\Py\rewrite\scripts\replace.py", line 724, in display_edit_counter pywikibot.output(u'\n%s pages changed.' % bot.changed_pages) AttributeError: 'NoneType' object has no attribute 'output'
in compat it works well
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
Maarten Dammers maarten@mdammers.nl changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |maarten@mdammers.nl
--- Comment #1 from Maarten Dammers maarten@mdammers.nl --- I was able to reproduce this. I ran pwb.py replace.py -lang:commons -family:commons -regex "(|\s*Wikidata\s*=\s*)(\d+)" "\1Q\2" -usercontribs:Dexbot -summary:"Adding missing Wikidata Q"
After reviewing several edits (y,y,y), I switched to always (a).
It did quite a few edits and when it was supposed to stop and output some statistics:
No changes were necessary in [[Creator:Zamfir C. Arbure]] Exception in thread Put-Thread: Traceback (most recent call last): File "C:\Python27\lib\threading.py", line 552, in __bootstrap_inner self.run() File "C:\Python27\lib\threading.py", line 505, in run self.__target(*self.__args, **self.__kwargs) File "C:\pywikibot\coredev\pywikibot__init__.py", line 679, in async_manager request(*args, **kwargs) File "C:\pywikibot\coredev\scripts\replace.py", line 724, in display_edit_coun ter pywikibot.output(u'\n%s pages changed.' % bot.changed_pages) AttributeError: 'NoneType' object has no attribute 'output'
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
Maarten Dammers maarten@mdammers.nl changed:
What |Removed |Added ---------------------------------------------------------------------------- Priority|Unprioritized |Normal Summary|interwiki option causes |replace.py |error |display_edit_counter throws | |AttributeError: 'NoneType' | |object has no attribute | |'output'
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
--- Comment #2 from Maarten Dammers maarten@mdammers.nl --- The relevant code:
pywikibot.Site().login() bot.run()
def display_edit_counter(bot): pywikibot.output(u'\n%s pages changed.' % bot.changed_pages)
# Queue last request to display number of changed pages. pywikibot.async_request(display_edit_counter, bot)
(why are we using subfunctions?)
pywikibot.async_request is in _init_.py . Is this caused by the fact that _init_.py doesn't iport pywikibot?
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
--- Comment #3 from Maarten Dammers maarten@mdammers.nl --- https://gerrit.wikimedia.org/r/#/c/165654/ seems to be the changeset that introduced this functionality and bug.
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
--- Comment #4 from Merlijn van Deen valhallasw@arctus.nl --- Seems to be a scoping issue -- replace.py (and thus most of the things inside it, including the pywikibot import) is unloaded when replace.py ends... which is before the function is called. Two options to solve this:
1) Explicitly call pywikibot.stopme() at the end of replace.py. This will make sure the callback is triggered before replace.py is unloaded ...and then you can also juts do the output directly, which is *much* cleaner. I.e. instead of
def display_edit_counter(bot): pywikibot.output(u'\n%s pages changed.' % bot.changed_pages)
# Queue last request to display number of changed pages. pywikibot.async_request(display_edit_counter, bot)
we'd have
pywikibot.stopme() pywikibot.output(u'\n%s pages changed.' % bot.changed_pages)
2) explicitly pass pywikibot so it's included in the scope, i.e.
def display_edit_counter(pywikibot, bot): pywikibot.output(u'\n%s pages changed.' % bot.changed_pages)
# Queue last request to display number of changed pages. pywikibot.async_request(display_edit_counter, pywikibot, bot)
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
--- Comment #5 from Gerrit Notification Bot gerritadmin@wikimedia.org --- Change 172044 had a related patch set uploaded by Mpaa: replace.py: fix display_edit_counter_feature
https://gerrit.wikimedia.org/r/172044
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
Gerrit Notification Bot gerritadmin@wikimedia.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |PATCH_TO_REVIEW
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
--- Comment #6 from Gerrit Notification Bot gerritadmin@wikimedia.org --- Change 172044 merged by jenkins-bot: replace.py: fix display_edit_counter_feature
https://gerrit.wikimedia.org/r/172044
https://bugzilla.wikimedia.org/show_bug.cgi?id=72942
Mpaa mpaa.wiki@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|PATCH_TO_REVIEW |RESOLVED CC| |mpaa.wiki@gmail.com Resolution|--- |FIXED
pywikipedia-bugs@lists.wikimedia.org