Page MenuHomePhabricator

api_tests.TestPropertyGenerator.test_two_continuations_limited fails with AttributeError
Open, HighPublicBUG REPORT


What happens?:

ERROR: test_two_continuations_limited (tests.api_tests.TestPropertyGenerator)
Test PropertyGenerator with many limited props and continuations.
Traceback (most recent call last):
  File "/home/travis/build/wikimedia/pywikibot/pywikibot/data/", line 1523, in _json_loads
    result = response.json()
  File "/home/travis/virtualenv/python3.7.9/lib/python3.7/site-packages/requests/", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/opt/python/3.7.9/lib/python3.7/json/", line 348, in loads
    return _default_decoder.decode(s)
  File "/opt/python/3.7.9/lib/python3.7/json/", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/python/3.7.9/lib/python3.7/json/", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/travis/build/wikimedia/pywikibot/tests/", line 639, in test_two_continuations_limited
    for pagedata in gen:
  File "/home/travis/build/wikimedia/pywikibot/pywikibot/data/", line 2740, in __iter__
    yield from super().__iter__()
  File "/home/travis/build/wikimedia/pywikibot/pywikibot/data/", line 2584, in __iter__ = self.request.submit()
  File "/home/travis/build/wikimedia/pywikibot/pywikibot/data/", line 1762, in submit
    result = self._json_loads(response)
  File "/home/travis/build/wikimedia/pywikibot/pywikibot/data/", line 1553, in _json_loads
    if value.isdigit():
AttributeError: 'int' object has no attribute 'isdigit'

Software version:
Python 3.7.9
Pywikibot 6.4.1.dev0

Event Timeline

Xqt triaged this task as High priority.Jul 2 2021, 9:04 AM

So obviously this happened due to some server problem and non-JSON response where JSON is expected (except ValueError in Request._json_loads). Why this happened is a mystery for me, but it isn't really important. Further down:

for param in self._params:
  if param.endswith('limit'):
    # param values are stored a list of str
    value = self[param][0]
    if value.isdigit():  # <-- this is where it crashes
>>> gen.request._params
{'titles': ['1298', '1816', '1881', '1941', '1948 Winter Olympics', '2013', '202
1 Western North America heat wave', '50 Greatest Players in NBA History', 'Abdur
 Razzaq Iskander', 'Adolf, King of the Romans', 'Albert I of Germany', 'Alkaliha
lobacillus', 'All About That Bass', 'Archaeological site', 'Assassination of Jam
es A. Garfield', 'Balderdash', 'Baltimore and Potomac Railroad', 'Basilicas in t
he Catholic Church', 'Bass Strait', 'Battle of Göllheim', 'Berlin to Kitchener n
ame change', 'COVID-19 pandemic', 'Calendar of saints', 'Carlo Maderno', 'Charle
s Tupper', 'Condominium', 'Contempt of court', 'Cultural Property (Japan)', 'Dea
ths in 2021', 'Donato Bramante'], 'prop': ['info', 'categoryinfo', 'langlinks',
'templates'], 'action': ['query'], 'indexpageids': [True], 'continue': ['', '',
'info', 'categoryinfo', 'templates', 'userinfo'], 'tllimit': [500], 'lllimit': [
'5'], 'meta': ['userinfo'], 'uiprop': ['blockinfo', 'hasmsg'], 'maxlag': ['5'],
'format': ['json'], 'llcontinue': ['68048055', 'ko'], 'tlcontinue': ['65984422',
 '10', 'SDcat']}
>>> {key: value for key, value in gen.request._params.items() if key.endswith('l
{'tllimit': [500], 'lllimit': ['5']}  # <--- int and str, respectively

So "param values are stored a list of str" isn't always truth.