jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/705155 )
Change subject: [bugfix] Ignore throttle.pid if a Site object cannot be created ......................................................................
[bugfix] Ignore throttle.pid if a Site object cannot be created
- raise a ValueError if either code or family cannot be found to create a Site object within pywikibot.Site constructor - ignore throttle.pid if a Site object cannot be created within bot.init_handlers
Bug: T286848 Change-Id: I53a7fb5cb2de484bf91d85ab0da14372b12b1eb7 --- M pywikibot/__init__.py M pywikibot/bot.py 2 files changed, 16 insertions(+), 8 deletions(-)
Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 305a950..048c92f 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -1148,6 +1148,8 @@ URL. Still requires that the family supporting that URL exists. :raises ValueError: URL and pair of code and family given :raises ValueError: Invalid interface name + :raises ValueError: Missing Site code + :raises ValueError: Missing Site family """ _logger = 'wiki'
@@ -1169,6 +1171,10 @@ code = code or _config.mylang fam = fam or _config.family
+ if not (code and fam): + raise ValueError('Missing Site {}' + .format('code' if not code else 'family')) + if not isinstance(fam, Family): fam = Family.load(fam)
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index e49315f..d189610 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -366,14 +366,16 @@
# if user has enabled file logging, configure file handler if module_name in config.log or '*' in config.log: - if pywikibot.Site.__doc__ == 'TEST': # set by aspects.DisableSiteMixin - pid = '' - else: - # get PID - throttle = pywikibot.Site().throttle # initialize a Throttle obj - pid = throttle.get_pid(module_name) # get the global PID if needed - pid = str(pid) + '-' if pid > 1 else '' - + pid = '' + if pywikibot.Site.__doc__ != 'TEST': # set by aspects.DisableSiteMixin + try: # T286848 + site = pywikibot.Site() + except ValueError: + pass + else: # get PID + throttle = site.throttle # initialize a Throttle obj + pid = throttle.get_pid(module_name) # get the global PID + pid = str(pid) + '-' if pid > 1 else '' if config.logfilename: # keep config.logfilename unchanged logfile = config.datafilepath('logs', config.logfilename)