Page MenuHomePhabricator

api_tests based on TestLazyLoginBase are failing
Closed, ResolvedPublicBUG REPORT

Description

TestLazyLoginNotExistUsername and TestLazyLoginNoUsername are failing. The reason is that read api permission is required since few hours. For example:
https://steward.wikimedia.org/w/api.php?action=query&meta=siteinfo&siprop=namespaces|namespacealiases|general&continue=&format=jsonfm
gives an error "code": "readapidenied" but unfortunately this error is not recognized when retrieving site info. The request above gives an empty dict.

This occures after rPWBC6761f988

The error is ignored by api.submit due to pywikibot.site.LoginStatus.IN_PROGRESS but not handled accordingly by LoginManager

C:\pwb\GIT\core>py -3 pwb.py api_tests -v TestLazyLoginNotExistUsername
tests: max_retries reduced from 15 to 1
test_access_denied_notexist_username (__main__.TestLazyLoginNotExistUsername)
Test the query with a username which does not exist. ...
steward:steward
/w/api.php?action=query&meta=siteinfo&siprop=namespaces|namespacealiases|general&continue=
{}
ERROR

======================================================================
ERROR: test_access_denied_notexist_username (__main__.TestLazyLoginNotExistUsername)
Test the query with a username which does not exist.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\pwb\GIT\core\pywikibot\tools\__init__.py", line 525, in suppressed_func
    return func(*args, **kwargs)
  File "C:\Python38\lib\unittest\mock.py", line 1342, in patched
    return func(*newargs, **newkeywargs)
  File ".\tests\api_tests.py", line 1023, in test_access_denied_notexist_username
    self.assertRaises(pywikibot.NoUsername, req.submit)
  File "C:\Python38\lib\unittest\case.py", line 816, in assertRaises
    return context.handle('assertRaises', args, kwargs)
  File "C:\Python38\lib\unittest\case.py", line 202, in handle
    callable_obj(*args, **kwargs)
  File "C:\pwb\GIT\core\pywikibot\data\api.py", line 1938, in submit
    self._add_defaults()
  File "C:\pwb\GIT\core\pywikibot\data\api.py", line 1479, in _add_defaults
    and self.site.mw_version >= '1.25wmf5'):
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 2778, in mw_version
    mw_ver = MediaWikiVersion(self.version())
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 2750, in version
    version = self.siteinfo.get('generator',
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 1690, in get
    preloaded = self._get_general(key, expiry)
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 1638, in _get_general
    self._cache[prop] = default_info[prop]
KeyError: 'namespaces'

----------------------------------------------------------------------
Ran 1 test in 0.512s

FAILED (errors=1)
C:\pwb\GIT\core>py -3 pwb.py api_tests -v TestLazyLoginNoUsername
tests: max_retries reduced from 15 to 1
test_access_denied_no_username (__main__.TestLazyLoginNoUsername)
Test the query without a username. ...
steward:steward
/w/api.php?action=query&meta=siteinfo&siprop=namespaces|namespacealiases|general&continue=
{}
ERROR

======================================================================
ERROR: test_access_denied_no_username (__main__.TestLazyLoginNoUsername)
Test the query without a username.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\pwb\GIT\core\pywikibot\tools\__init__.py", line 525, in suppressed_func
    return func(*args, **kwargs)
  File "C:\Python38\lib\unittest\mock.py", line 1342, in patched
    return func(*newargs, **newkeywargs)
  File ".\tests\api_tests.py", line 1052, in test_access_denied_no_username
    self.assertRaises(pywikibot.NoUsername, req.submit)
  File "C:\Python38\lib\unittest\case.py", line 816, in assertRaises
    return context.handle('assertRaises', args, kwargs)
  File "C:\Python38\lib\unittest\case.py", line 202, in handle
    callable_obj(*args, **kwargs)
  File "C:\pwb\GIT\core\pywikibot\data\api.py", line 1938, in submit
    self._add_defaults()
  File "C:\pwb\GIT\core\pywikibot\data\api.py", line 1479, in _add_defaults
    and self.site.mw_version >= '1.25wmf5'):
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 2778, in mw_version
    mw_ver = MediaWikiVersion(self.version())
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 2750, in version
    version = self.siteinfo.get('generator',
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 1690, in get
    preloaded = self._get_general(key, expiry)
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 1638, in _get_general
    self._cache[prop] = default_info[prop]
KeyError: 'namespaces'

----------------------------------------------------------------------
Ran 1 test in 0.518s

FAILED (errors=1)

Event Timeline

Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald Transcript
Xqt triaged this task as High priority.Mar 31 2020, 6:02 AM

Why does siteinfo not ask API for siteinfo?

Why does siteinfo not ask API for siteinfo?

It does it in site/__init__.py line 1552

In this special test it is expected to fail that call because steward wiki neads read permission, see These tests.

There is also a note for T100965

until the KeyError siteinfo never calls API

It seems as another cycle. siteinfo keeps calling itself from various places

Yeah, login calls submit calls _add_default_params calls siteinfo outputs readapidenied calls login

Change 584885 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[pywikibot/core@master] [bugfix] Let clientlogin handle APIError class instead of response

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

Dvorapa moved this task from Backlog to Test failures on the Pywikibot-tests board.
Dvorapa changed the subtype of this task from "Task" to "Bug Report".

Change 584885 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Let clientlogin handle APIError class instead of response

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