Page MenuHomePhabricator

proofreadpage_tests.TestPageOCR fails due to UnboundLocalError
Closed, ResolvedPublic

Description

ERROR: test_do_ocr_phetools (tests.proofreadpage_tests.TestPageOCR)
5903Test page._do_ocr(ocr_tool='phetools').
5904----------------------------------------------------------------------
5905Traceback (most recent call last):
5906 File "c:\projects\pywikibot-g4xqx\tests\proofreadpage_tests.py", line 399, in test_do_ocr_phetools
5907 error, text = self.page._do_ocr(ocr_tool='phetools')
5908 File "c:\projects\pywikibot-g4xqx\pywikibot\proofreadpage.py", line 698, in _do_ocr
5909 return self._ocr_callback(cmd_uri, ocr_tool=ocr_tool)
5910 File "c:\projects\pywikibot-g4xqx\pywikibot\proofreadpage.py", line 621, in _ocr_callback
5911 if 400 <= response.status < 600:
5912UnboundLocalError: local variable 'response' referenced before assignment
5913
5914---------------------------------------------------------------------

https://ci.appveyor.com/project/Ladsgroup/pywikibot-g4xqx/builds/30294981/job/w51g1s1hehuovyd0

Event Timeline

Xqt triaged this task as High priority.Jan 24 2020, 11:05 PM

@Xqt Hi! As you've listed this task as a good first task, more details in the task description are welcome. Maybe add where and how one can reproduce this error, link to the codebase, some hints/ideas for fixing the issue, etc. It might be easier that way for a newcomer to get started :)

If you think this task may not be too easy for a newcomer, consider removing the good first task tag.

See https://gerrit.wikimedia.org/r/plugins/gitiles/pywikibot/core/+/2d2a818c10689187439b681aee73f542effb36d2/pywikibot/proofreadpage.py

The whole loop in line 603 has finished after 5 retried but the code must not continue with line 621 which is noted in trackback above it must just return with the other failing exception inside the while loop like:

for retries in range(5):
  try:
    <read the data>
  except <Exception1>:
    return <values for this>
  except <Exception2>:
    pass
  else:
    break
else:
  return <values for that max retries of Exeption2>

continue the method

Change 567213 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Fix UnboundLocalError in ProofreadPage._ocr_callback

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

Change 567213 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Fix UnboundLocalError in ProofreadPage._ocr_callback

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