Page MenuHomePhabricator

Do not set Bot._site to None if we already have a site object
Closed, ResolvedPublic

Description

replace.ReplaceRobot always needs a site argument. This is due to the ReplaceRobot's constructor in replace.py is called positional and not as keywords argument. This leads to template.TemplateRobot resets bot.site to None when the constructor calls the ReplaceRobot.init.

Samples:

>>> import pwb, pywikibot as py
>>> site = py.Site()
>>> from scripts.template import TemplateRobot
>>> bot = TemplateRobot(iter([]), {}, **{})  # call the bot without site argument
WARNING: Bot.site was not set before being retrieved.
WARNING: Using the default site: wikipedia:de
# the bot._site has been set
>>> bot.site
WARNING: Bot.site was not set before being retrieved.
WARNING: Using the default site: wikipedia:de
# but it was lost immediately

try it with site argument:

>>> del bot
>>> bot = TemplateRobot(iter([]), {}, site=site, **{})
# looks good here
>>> bot.site
WARNING: Bot.site was not set before being retrieved.
WARNING: Using the default site: wikipedia:de
# but it fails again

Event Timeline

Xqt created this task.Jan 28 2016, 7:27 AM
Xqt claimed this task.
Xqt raised the priority of this task from to Normal.
Xqt updated the task description. (Show Details)
Xqt added a subscriber: Xqt.
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptJan 28 2016, 7:27 AM
Xqt updated the task description. (Show Details)Jan 28 2016, 7:28 AM
Xqt set Security to None.

Change 266994 had a related patch set uploaded (by Xqt):
[bugfix] Don't reset Bot._site to None if we have already a site object

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

Xqt renamed this task from Do not set Bot._site to None if we already a site object to Do not set Bot._site to None if we already have a site object.Jan 28 2016, 9:25 AM

Change 266998 had a related patch set uploaded (by Xqt):
[BREAK][bugfix] Bot class arguments for constructor

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

Change 266998 merged by jenkins-bot:
[bugfix] Bot class arguments for constructor

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

Dalba closed this task as Resolved.Aug 23 2018, 10:13 AM

Change 266994 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Don't reset Bot._site to None if we have already a site object

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

The same issue seems to appear with image.py. Command line:

python pwb.py scripts/image.py 'FireHouse 02.jpg' -lang:it -family:wikipedia -summary:"Cancellazione di massa di file sospetti"


WARNING: family and mylang are not set.
Defaulting to family='test' and mylang='test'.
WARNING: /Users/ruthven/Development/core_stable/pywikibot/data/api.py:281: UserWarning: Unexpected overlap between action and query submodules: frozenset([u'globalpreferences', u'readinglists'])
WARNING: Bot.site was not set before being retrieved.
WARNING: Using the default site: wikipedia:it

Xqt added a comment.Dec 23 2018, 6:14 PM

The same issue seems to appear with image.py. Command line:

python pwb.py scripts/image.py 'FireHouse 02.jpg' -lang:it -family:wikipedia -summary:"Cancellazione di massa di file sospetti"

Seems your bot is outdated. This Userwarning is no longer in api.py. The bot works for me:

C:\pwb\GIT\core>pwb.py image Kellerskreuz.jpg -simulate -lang:de -family:wikipedia
family and mylang are not set.
Defaulting to family='test' and mylang='test'.
Retrieving 3 pages from wikipedia:de.
No changes were necessary in [[Steinkreuz]]