Last modified: 2014-11-10 22:36:47 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T74942, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 72942 - replace.py display_edit_counter throws AttributeError: 'NoneType' object has no attribute 'output'
replace.py display_edit_counter throws AttributeError: 'NoneType' object has ...
Status: RESOLVED FIXED
Product: Pywikibot
Classification: Unclassified
pagegenerators (Other open bugs)
core-(2.0)
All All
: Normal normal
: ---
Assigned To: Pywikipedia bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-11-04 10:00 UTC by JAn Dudík
Modified: 2014-11-10 22:36 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description JAn Dudík 2014-11-04 10:00:19 UTC
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
Comment 1 Maarten Dammers 2014-11-08 12:14:01 UTC
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'
Comment 2 Maarten Dammers 2014-11-08 12:22:58 UTC
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?
Comment 3 Maarten Dammers 2014-11-08 12:30:16 UTC
https://gerrit.wikimedia.org/r/#/c/165654/ seems to be the changeset that introduced this functionality and bug.
Comment 4 Merlijn van Deen (test) 2014-11-08 12:46:01 UTC
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)
Comment 5 Gerrit Notification Bot 2014-11-08 20:15:32 UTC
Change 172044 had a related patch set uploaded by Mpaa:
replace.py: fix display_edit_counter_feature

https://gerrit.wikimedia.org/r/172044
Comment 6 Gerrit Notification Bot 2014-11-09 04:09:49 UTC
Change 172044 merged by jenkins-bot:
replace.py: fix display_edit_counter_feature

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

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links